Is it possible for each dropdown options to link somewhere when selected without the need for an external button?
<select> <option value="x">x</option> <option value="y">y</option> </select>
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.
The <select> tag creates a dropdown list. You can't put html links inside a dropdown. Save this answer.
We can keep one dropdown listbox for the users to select one area ( option ) and then the script will redirect the page to that section. 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 <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue.
You can use the onChange property. Something like:
<select onChange="window.location.href=this.value"> <option value="www.google.com">A</option> <option value="www.aol.com">B</option> </select>
Add an onchange event handler and set the pages location to the value
<select id="foo"> <option value="">Pick a site</option> <option value="http://www.google.com">x</option> <option value="http://www.yahoo.com">y</option> </select> <script> document.getElementById("foo").onchange = function() { if (this.selectedIndex!==0) { window.location.href = this.value; } }; </script>
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