Jump to content

[SOLVED] Form Drop Down Menu in which Selection Immediately Links to New Page?


PrimeR

Recommended Posts

 

How do you create a drop down menu in which the array selections contain links?

 

(In other words, it's like a regular form drop down menu with a list of products for example, except selecting an option from it immediately takes the user to the info page for the product selected.  No submit button needed.)

This is a javascript question not a PHP question.  You can use the select element's onchange event to trigger an even that will change location.href.

 

i.e.

 

<script type="text/javascript">
function changeLocation() {
    var select = document.getElementById("myselect");
    var href = select.options[select.selectedIndex].value;
    location.href = href;
}
</script> 
<select id="myselect" onchange="changeLocation()">
    <option value="http://www.google.com">Google</option>
</select>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.