Jump to content

Dropdown menu with links


Fire Dragon

Recommended Posts

I tried make dropdown list to my website,I success create menu itself,but I have problems to create menu's options to links.

<form><select name="R/S 252-386"><OPTION> 252 <OPTION> 253<OPTION> 254 </select>

Here was my code.I can't find how change options to links.I saw one JS example,but after you select you must press button "GO!" etc.I want code,what sends you immediately to next page,after you selected something.Do I need JS for this,or can I create it only with HTML?Thanks.

Link to comment
Share on other sites

I tried make dropdown list to my website,I success create menu itself,but I have problems to create menu's options to links.
<form><select name="R/S 252-386"><OPTION> 252 <OPTION> 253<OPTION> 254 </select>

Here was my code.I can't find how change options to links.I saw one JS example,but after you select you must press button "GO!" etc.I want code,what sends you immediately to next page,after you selected something.Do I need JS for this,or can I create it only with HTML?Thanks.

thats because you can't...you need to use the onchange event of the list and redirect based on the slected option
Link to comment
Share on other sites

just use this

<html><head>	<title>test</title></head><body><select onchange="window.location=this[this.selectedIndex].value">	<option value="#">Choose a serach engine</option>	<option value="http://www.google.ca">Google</option>	<option value="http://www.msn.ca">MSN</option>	<option value="http://www.askjeeves.com">Ask Jeeves</option></select></body></html>

Link to comment
Share on other sites

just use this
<html><head>	<title>test</title></head><body><select onchange="window.location=this[this.selectedIndex].value">	<option value="#">Choose a serach engine</option>	<option value="http://www.google.ca">Google</option>	<option value="http://www.msn.ca">MSN</option>	<option value="http://www.askjeeves.com">Ask Jeeves</option></select></body></html>

That <select onchange="window.location=this[this.selectedIndex].value"> is pretty nifty.Although I haven't used forms as a means of linking in a very long time, I used to use <select name="dropdown" onchange="location.href=(form.dropdown.options[form.dropdown.selectedIndex].value)">But your way seems more efficiant as it uses slightly less code :)
Link to comment
Share on other sites

That <select onchange="window.location=this[this.selectedIndex].value"> is pretty nifty.Although I haven't used forms as a means of linking in a very long time, I used to use <select name="dropdown" onchange="location.href=(form.dropdown.options[form.dropdown.selectedIndex].value)">But your way seems more efficiant as it uses slightly less code :)

I didn't use the 'this' object for a long time but it saves many headaches once you master it...it is an instance of the current object you are working with.It is great when writing unobtrusive JS.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...