Solved

Link Pages with  <select>?????

Posted on 2000-04-02
4
273 Views
Last Modified: 2010-04-09
Hi
How can I Make a list with links with the <select>-command? My current version:
<select>
<option><a href="URL1">Name</a>
<option><a href="URL2">Name2</a>
...
</select>

It doesn't work. How to do it right?
Thanx
0
Comment
Question by:tiefenauer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:Hardaway
ID: 2677748
Try this,

<select name="select" onChange="location = this.options this.selectedIndex].value;">            <option selected>Select one</option>
<option value="Option2.html">Option 2</option>
<option value="Option3.html">Option 3</option>
.......
</select>

Hope this help.
0
 
LVL 7

Expert Comment

by:nettrom
ID: 2679245
how you solve this depends on whether you want the solution to be run on the client side or the server side.  if it's the latter you'll have to have a submit-button saying "Go!" (or something like that), and then a small form handler that outputs the needed Location-header so the browser gets redirected to the other location.

if you want to do it on the client side, Hardaway's suggestion is one possible solution.  I prefer to do it slightly differently though, using a small function to do the job.  it checks for empty values, making you easily able to have spacers in your code.

script code:

<script type="text/javascript">
function go(mySelect) {
  var myValue = mySelect[mySelect.selectedIndex].value;
  if(myValue != "") {
    location = myValue;
  }
}
</script>

and then use a select like this:

<select onchange="go(this)">
<option value="">Please select your destination</option>
<option value="page1.html">Page #1</option>
<option value="page2.html">Page #2</option>
<option value=""> -- Spacer -- </option>
<option valu="page3.html">Page #3</option>
</select>
0
 
LVL 1

Accepted Solution

by:
Whitewolf earned 10 total points
ID: 2679376
Your code from the beginning is fine, what you need to do is just put the close option tag after each option. Right now, it can't find it and thus won't work.

<option>
<a href="url1">Option1</a>
</option>


Hope this helps,
Whitewolf
0
 
LVL 7

Expert Comment

by:nettrom
ID: 2679426
the closing tag on option elements is optional (pun not intended).  so, the next opening tag for <option> implicitly closes the previous one.
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question