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
});
精彩评论