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?
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'>Google</option>
<option value='http://stackoverflow.com'>Stack Overflow</option>
<option value='http://microsoft.com'>Microsoft</option>
</select>
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;
}
精彩评论