15

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);
        }
    });
});
Sooraj Abbasi
  • 110
  • 16
user547794
  • 14,263
  • 36
  • 103
  • 152
  • 3
    I know these kind of comments are frowned upon, but nevertheless: Googling for `jquery change` would have given you the link to the `change()` function as first hit: http://api.jquery.com/change/ – Felix Kling Feb 06 '11 at 01:02

3 Answers3

34

Use change() instead of click():

jQuery(document).ready(function(){
  $("#otherCatches").change(function() {
    $.ajax({
     url: "otherCatchesMap.php>",
     success: function(msg){
       $("#results").html(msg);
     }
   });
  });
});
Christopher
  • 2,005
  • 3
  • 24
  • 50
Pan Thomakos
  • 34,082
  • 9
  • 88
  • 85
23

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

$(function() {
    $("#otherCatches").change(function() {
       $(this).val() // how to get the value of the selected item if you need it
    });
});
Robin
  • 21,667
  • 10
  • 62
  • 85
12

$("#otherCatches").change(function () {
    //// Your code        
});

Jith
  • 1,701
  • 3
  • 16
  • 22