开发者

Run jQuery function on drop down change

开发者 https://www.devze.com 2023-02-09 00:39 出处:网络
I wrote a jQuery function tha开发者_高级运维t 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:

I wrote a jQuery function tha开发者_高级运维t 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);
        }
    });
});


Use change() instead of click():

jQuery(document).ready(function(){
  $("#otherCatches").change(function() {
    $.ajax({
     url: "otherCatchesMap.php>",
     success: function(msg){
       $("#results").html(msg);
     }
   });
  });
});


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

$(function() {
    $("#otherCatches").change(function() {
       $(this).val() // how to get the value of the selected item if you need it
    });
});



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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号