Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run jQuery function on drop down change

I wrote a jQuery function that currently runs on Click Event. I need to change it so that it runs when a drop down box (Select- Option) value is changed. Here is my code:

<form id="form1" name="form1" method="post" action="">
  <label>
    <select name="otherCatches" id="otherCatches">
      <option value="*">All</option>
    </select>
  </label>
</form>

$("#otherCatches").click(function() {
    $.ajax({
        url: "otherCatchesMap.php>",
        success: function(msg) {
            $("#results").html(msg);
        }
    });
});
like image 759
user547794 Avatar asked Feb 06 '11 00:02

user547794


2 Answers

Use change() instead of click():

jQuery(document).ready(function(){
  $("#otherCatches").change(function() {
    $.ajax({
     url: "otherCatchesMap.php>",
     success: function(msg){
       $("#results").html(msg);
     }
   });
  });
});
like image 155
Pan Thomakos Avatar answered Oct 14 '22 07:10

Pan Thomakos


http://api.jquery.com/change/

$(function() {
    $("#otherCatches").change(function() {
       $(this).val() // how to get the value of the selected item if you need it
    });
});
like image 31
Robin Avatar answered Oct 14 '22 07:10

Robin