0

I have the following script that is not working in IE 8, it works in other browsers fine but in IE 8... all the user gets, even with the checkbox input selected is alert. Any thoughts would be greatly appreciated.

$(function() {
    $("form#insider-account").bind("keypress", function(e) {
       if (e.keyCode == 13) return false;
    });

   var isChecked = false;

   $("form#insider-account").change(function() {
      if ($("input#insideraccount_verified").is(":checked")) {
         isChecked = true; 
      } else {
         isChecked = false;   
      }
   });

   $("form#insider-account").submit(function(e) {
      if (!isChecked) {
         e.preventDefault();
         alert("You must agree that the information you provided is correct.");
      }
      else {

      }
   });
});
philecker
  • 49
  • 1
  • 7

2 Answers2

2

Not sure why you set isChecked in a separate event from the submit-event. I think your problem is that in IE8, this:

 $("form#insider-account").change(...

Isn't triggered when a control inside the form is changed. Why not attach the change event to the control itself:

$("input#insideraccount_verified").change(...

Or, better, just check that the checkbox is checked in the submit event instead of using a variable that you set in some other event:

$("form#insider-account").submit(function (e) {
            if (!$("input#insideraccount_verified").is(":checked")) {
                e.preventDefault();
                alert("You must agree that the information you provided is correct.");
            }
            else {

            }
        });
Stefan
  • 1,719
  • 2
  • 15
  • 27
0

Listen for change on elements inside the form instead of the form iteself, after searching google for "form change ie jquery" there were a number of results stating that this was an issue including jQuery .change() event not firing in IE

It's suggested there to use the on event instead, which will listen to the change event for input elements inside your form, like so:

$("form#insider-account input").on('change', function() {
    isChecked = $("input#insideraccount_verified").is(":checked");
});
Community
  • 1
  • 1
zachallia
  • 1,495
  • 12
  • 16
  • Your code seems to do the same thing mine did, works in Chrome, but doesn't work in IE 8. – philecker Dec 06 '13 at 15:41
  • If it doesn't bubble the way he's currently doing it, it won't work this way either as it depends on that same bubbling. In a sense it's identical to what's in the OP. the edit is better. – Kevin B Dec 06 '13 at 15:47
  • @KevinB true.. i was going off the suggestions in that thread. Edited to be directly listening to the input changes. – zachallia Dec 06 '13 at 15:49