2

I have following jquery code, where on click of a check box I will show a popup value.

Except in IE,in all other browser it works as expected. That is, on change the check box will be checked and the popup will be opened.

However in IE8 its not getting checked, however popup is displayed properly.

Code :

$('#TAndC').change(function(){

    if( $('input[name="TAndC"]').is(':checked')) 
    {
         $('#TandCBox').show();
         var termsandcondition = GetEnum().TermsandConditionsPageId;
         var actionURL = '@Url.Action("ShowTAndC", "Account", new { isFromCheckBox = true })';
         $('.popUpForm').load(actionURL);
         var msgBox = $('#terms').attr('href');
         MaskMsgPopUp(msgBox);
         return false;
     }
});
2
  • Why are you returning false? Remove it and try. And please provide a jsfiddle or at least relevant HTML markup, what type of element is #TAndC, a checkbox, a textbox??? Commented Dec 19, 2013 at 11:01
  • Actually I just edited the names just before posting it here. Sorry for that. Will try the suggested methods. Commented Dec 19, 2013 at 11:20

2 Answers 2

6

If your element is a checkbox and not a dropdown then use click anyway.

If your selector is referring to a dropdown use click if you need to support IE8 and older.

See why that is below.

According to the MSDN for change/onchange, the event is not triggered until the change is committed.

In addition the event is also not triggered when the value is changed programmatically.

To quote:

This event is fired when the contents are committed and not while the value is changing. For example, on a text box, this event is not fired while the user is typing, but rather when the user commits the change by leaving the text box that has focus. In addition, this event is executed before the code specified by onblur when the control is also losing the focus. The onchange event does not fire when the selected option of the select object is changed programmatically. Changed text selection is committed.

To invoke this event, do one of the following:

  • Choose a different option in a select object using mouse or keyboard navigation.
  • Alter text in the text area and then navigate out of the object.

If you must support IE8 and older, you are probably better of to use the click event instead which get's triggered when you release the mouse and your new choice is selected.

Sign up to request clarification or add additional context in comments.

Comments

1

instead of .change use below code and try

$(document).ready(function(){

$(document).on('click','#TAndC',click_function){

 if( $('input[name="TAndC"]').is(':checked')) 
 {
      $('#TandCBox').show();
      var termsandcondition = GetEnum().TermsandConditionsPageId;
      var actionURL = '@Url.Action("ShowTAndC", "Account", new { isFromCheckBox = true })';
      $('.popUpForm').load(actionURL);
      var msgBox = $('#terms').attr('href');
      MaskMsgPopUp(msgBox);
      return false;
  }
 });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.