Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load page on selection from dropdown form

Tags:

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!

like image 561
JakeIC Avatar asked Apr 16 '12 13:04

JakeIC


People also ask

How do I redirect to another page from the option selected?

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.

How do I display content in a dropdown selection?

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.

How do you keep the selected option on page load?

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.

How do you add a link to a drop down menu in HTML?

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.


1 Answers

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'

like image 64
jacktheripper Avatar answered Sep 23 '22 06:09

jacktheripper