Forum Moderators: phranque

Message Too Old, No Replies

Form / Link Questoin

         

andmunn

3:24 am on Sep 5, 2004 (gmt 0)

10+ Year Member



I have a "drop down menu", i.e..// assume the following code:

<select>
<option>Link 1</option>
<option>Link 2</option>
</select>

How do i make it so that if any of the options is selected, it will go to that page?

Thanks :)
Andrew.

encyclo

2:24 pm on Sep 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need a bit of Javascript to make it work - so make sure you have a non-Javascript alternative available for those with JS disabled and for the bots.

Here's the Javascript, placed in the head or an external file:

function gotoPage( menuform ) 
{
var baseurl = "http://www.example.com" ;
selecteditem = menuform.newurl.selectedIndex ;
newurl = menuform.newurl.options[ selecteditem ].value ;
if (newurl.length!= 0) {
location.href = baseurl + newurl ;
}
}

And your HTML will look something like this:

<form action=""> 
<p><select name="newurl" onchange="gotoPage(this.form)">
<option value="/path/to/file1.html">Link 1</option>
<option value="/path/to/file2.html">Link 2</option>
</select></p>
</form>

Just place your base path in the place of the example.com, and then in the value part of the option, place the rest of the path from the base path to the file.

andmunn

7:20 pm on Sep 5, 2004 (gmt 0)

10+ Year Member



Thanks for the quick reply - greatly appreciated - what would a "non javacsript" alternative constitute? Do you mean doing this in such a way that a drop down menu isn't the only way to navigate?

Thanks,
Andrew.

encyclo

8:50 pm on Sep 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you will need to duplicate the links with standard
<a href="whatever.html">
links, perhaps as a footer on each page, or if there are a lot of links in your dropdown list, with a standard link to a "site plan" page where all the relevant links are posted.