Thursday, 15 April 2010

javascript - disable checkbox if input value is zero -



javascript - disable checkbox if input value is zero -

i have list of check-boxes created dynamically , there input field each check box want disable check box if input field value zero. below code

html code

<input class="check" id="check" name="check" type="checkbox"><label for="check">checkbox <input type="hidden" id="test" value="0" /></label> <input class="check" id="check1" name="check1" type="checkbox"><label for="check1">checkbox1 <input type="hidden" id="test" value="6" /></label>

jquery

if($("#test").val() == "0"){ $('.check').attr("disabled", "disabled"); }

jsfiddle

you used twice id=test , javascript works first of them.

change id=test class=test, or works 2 differents ids.

working code:

$('.test').each(function() { if ($(this).val() == '0') { $(this).parent().prev().attr('disabled', 'disabled'); } });

http://jsfiddle.net/cdd5l/

javascript jquery html

No comments:

Post a Comment