最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery check box change function not working in IE 8 - Stack Overflow

programmeradmin3浏览0评论

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;
     }
});

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;
     }
});
Share Improve this question asked Dec 19, 2013 at 10:56 TBATBA 1,1975 gold badges46 silver badges83 bronze badges 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??? – A. Wolff 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. – TBA Commented Dec 19, 2013 at 11:20
Add a ment  | 

2 Answers 2

Reset to default 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 mitted.

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

To quote:

This event is fired when the contents are mitted 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 mits 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 mitted.

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.

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;
  }
 });
});
发布评论

评论列表(0)

  1. 暂无评论