Solved

Link Pages with  <select>?????

Posted on 2000-04-02
4
268 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
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with this homework problem. 5 62
html border input line 7 26
Adding 1 the value of input "text" every 3 seconds 5 33
Link Anchor Not working 9 51
This article discusses how to create an extensible mechanism for linked drop downs.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

726 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