I am trying to make a drop down menu that takes me to various webpages. Right now it is set up so you make your selection and then you hit a "Go" button and then it takes you to the appropriate link. I am trying to figure out how to make it so when you make your selection it automatically goes and you don't need to push the "Go" button.
Here is what I have:
<p align="center"> <form name="jump" class="center"> <select name="menu"> <option value="#">Select an option</option> <option value="/link1.shtml">Link 1</option> <option value="/link2.shtml">Link 2</option> <option value="/link3.shtml">Link 3</option> </select> <input type="button" onClick="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO"> </form> </p>
Any help or links to explanations would be great. Thank you!
This is done by using onChange event of dropdown listbox. Once the user selection one option then by onChange event we run one function SelectRedirect(). The function will receive the user selected option value like this. Here we have used getElementById to get the value of the selected option.
In order to display data/content of a specific element by selecting the particular dropdown menu in jQuery, we can use the with following ways: Using hide() and show() methods: hide() methods : This method is used to hiding the syntax or the element of html that you want to hide.
Per your updated question use localStorage or cookies to hold the selected value. When the page refreshes, check for the cookie or localStorage value and load it. Save this answer.
Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.
Try the following:
<select onchange="location = this.options[this.selectedIndex].value;"> <option>Please select</option> <option value="http://www.apple.com/">Apple</option> <option value="http://www.bbc.com">BBC</option> <option value="http://www.facebook.com">Facebook</option> </select>
What you were looking for was 'onchange' instead of 'onsubmit'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With