javascriptjqueryhtmldrop-down-menu

How can I navigate based on select element option clicks?


I am wanting to write some jQuery code that converts a HTML

<select> 
  <option> Blah </option> 
</select>

combo box into something (probably a div) where selecting an item acts the same as clicking a link.

I guess you could probably use JavaScript to handle a selection event (my JavaScript knowledge is a little in disrepair at the moment) and 'switch' on the value of the combo box but this seems like more of a hack.

How can I go about this?


Solution

  • The simple solution is to use

    $("#mySelect").change(function() {
      document.location = this.value;
    });
    

    This creates an onchange event on the select box that redirects you to the url stored in the value field of the selected option.