简体   繁体   中英

Onchange w/jquery does not fire

I am having this issue getting my ajax to fire after a change from a select menu. Click works fine and I can get the ajax to fire with no issues when using the "click" method. I have tried in all browsers and none work using change...Totally stumped!

Here is my code

<script>
$(document).ready(function(){
    $("#ModelID").change(function(){
        var ModelID = $('#ModelID').val();
        var dataString = 'ModelID='+ ModelID;
        {
             jQuery.ajax({
                 type: "POST",
                 url: "ajax/PTO_App_Model.php",
                 data: dataString,
                 cache: false,
                 success: function(html)
                 {
                     $("#show_model").html(html).show();
                     $("#show_model").slideDown("slow");
                 }
             });
         }
         return false; 
     });
 });
 </script>

Here is the HTML Form Select

<select name="ModelID" id="ModelID">
  <option value="205">Model One</option>
  <option value="206">Model Two</option>
  <option value="207">Model Three</option>
</select>

The code looks good, and seems to work http://jsfiddle.net/uGr6U/1/

Could you try some debugging to see what is going on in the change event?

Are you sure that the event is not firing? Perhaps there is a problem occurring during the fire and you don't see anything happen?

I made a simple test case using your HTML and Javascript (replacing the ajax code with an alert) and it works fine in Seamonkey, IE9, IE8, Chrome and Firefox 6.

I'd try adding some alert statements to verify which parts of the code are being called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM