views:

23

answers:

2

Hey

I am not JS expert.. I want when I select a < option> in < select> it will pass the user to another page.

How can I do it?

A: 

If you just want to change the url whenever an option is selected, you could use something like this:

<select onChange="javascript:document.location=this.value;">
<option value='http://google.com'&gt;Google&lt;/option&gt;
<option value='http://stackoverflow.com'&gt;Stack Overflow</option>
<option value='http://microsoft.com'&gt;Microsoft&lt;/option&gt;
</select>
Chris Hendry
I mean each option will pass to another URL. How can I do it? Thank you.
Luis
I Edited my answer to reflect your clarification.
Chris Hendry
Thank you. Working well.
Luis
A: 

You should have something like that:

<select id="theSelect">
  <option value="/pathTo/page1.html">page 1</option>
  <option value="/pathTo/page2.html">page 2</option>
</select>

Then on the select set an onchange event:

var sel = document.getElementById('theSelect');
sel.onchange = function(e){
  window.location.href = sel.options[sel.selectedIndex].value;
}
Mic
Thank you, But it doesn't work.... :-)
Luis
Strange... it works here 8) And put the event handler inside the HTML is not a good habit to start with.
Mic