Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using jquery, How to redirect when drop down list selection changes?

I have a drop down list, if someone selects an option I want to redirect to another page based on the selection.

How can I do this via jquery?

like image 783
Blankman Avatar asked Nov 28 '22 10:11

Blankman


2 Answers

Bind the logic to the $.change() event, and get the current value from $.val() to determine where the user ought to be redirected to. This example assumes a location is stored directly in the value itself.

$(".mySelect").change(function(e){
  window.location = $(this).val();
});
like image 98
Sampson Avatar answered Dec 05 '22 18:12

Sampson


<select id="abc">
    <option value="p1">Page 1</option>
    <option value="p2">Page 2</option>
    <option value="p3">Page 3</option>
</select>

$("#abc").change(function() {
    window.location.href = "http://domain/" + $(this).val() + ".html";
});
like image 44
Crozin Avatar answered Dec 05 '22 18:12

Crozin