Click event on checkbox doesn't function on IE

Good morning, I have a checkbox defined with this instruction:

echo CHtml::activeCheckBox('myClass', 'myField', array('submit'=>Yii::app()->getRequest()->url));

when the checkbox is changed it should submit the form, but it does nothing with Internet Explorer while it functions perfectly in Firefox. It was also functioning with Internet Explorer with Yii version 1.1.0 before I upgrade to Yii 1.1.1.

I think the problem is related to upgrade of jquery to 1.4.2, if I see the code now it generate a code like this:

jQuery('#myClass_myField').live('click',function(){jQuery.yii.submitForm(this,'/myUrl',{});return false;});

instead in 1.1.0 this was the code:

jQuery('#myClass_myField').click(function(){jQuery.yii.submitForm(this,'/myUrl',{});return false;});

As I’m not a Jquery expert I don’t understand if it’s a Jquery bug or it is caused by an incorrect use in Yii.

Thanks for help.

You should give your IE version.

If I remember well, live() has some known problems. Some events (e.g. “change”) don’t work on all browsers, it may be the same for “click”. So I guess it’s a jQuery bug.

But I don’t know why Yii produces such js code: the activeCheckBox isn’t added dynamically, so I see no reason to use live() instead of click(). Well, that’s just my thoughts, there’s probably a good reason that I can’t see.

I’m using internet explorer 6 (because my company still use this old version), I don’t have at the moment the possibility to test on a newer explorer version.

I found that to cause the problem is the presence in the same form of an activeDropdownlist:

echo CHtml::activeDropDownList('myClass', 'myDrop', array('sc1'=>'value1', 'sc2'=>'value2'), array('submit'=>'', 'prompt'=>'Choose..'));  

that generate this Jquery code:

jQuery('#myClass_myDrop').live('change',function(){jQuery.yii.submitForm(this,'',{});return false;});

The change event on the dropdownlist functions with no problem but it seems in Internet Explorer to go in conflict with the checkbox because if I comment the dropdownlist the click event on checkbox return to function again

I don’t know the reason and how to solve the problem.

At the end I solved the problem by changing the activeCheckBox from this

echo CHtml::activeCheckBox('myClass', 'myField', array('submit'=>Yii::app()->getRequest()->url));

to this:

  echo CHtml::activeCheckBox('myClass', 'myField', array('onclick'=>'"_self";  this.form.action="'.Yii::app()->getRequest()->url.'"; this.form.submit();'));

So I eliminated the attribute ‘submit’ and I managed manually the submit with javascript on the ‘onclick’ event.

In this way it functions in all browsers, I hope this will be useful to others.