The code below works in FF, Safari, Chrome. But IE is giving me issues.
When a checkbox is checked, I cannot get IE to detect it.
$("#checkbox_ID").change(function(){
if($('#'+$(this).attr("id")).is(':checked'))
{
var value = "1";
}
else
{
var value = "0";
}
alert(value);
return false;
});
Simply, I’m not getting that alert popup, as expected.
I’ve even tried it this way:
$("#checkbox_ID").change(function(){
if( $('#'+$(this).attr("id")'+:checked').attr('checked',false))
{
var value = "1";
}
else
{
var value = "0";
}
alert(value);
return false;
});
Here’s the simple checkbox input: <input class="prod" type="checkbox" name="checkbox_ID" id="checkbox_ID" value="1"/>
Anyone know if IE requires a different jquery method? or is my code just off?
As noted by sblom with IE7 and below you need the element to blur for this action to fire, later versions of IE and other browsers don’t need the element to explicitly lose focus, simply changing should fire this event (as shown in my below example).
I believe that your problem could be that you’re trying to access the ‘value’ variable when it is out of scope.
Here is a working preview, notice that because you return false at the end of the function it resets the checkbox to its previous value, as you have canceled the effect of the click.