The checkbox is not worked ,in jquery -


hello: have problem whit checkbox ,i tried make button when it's checked enable otherwise it's disable it's not worked well, when chekcked enable when unchecked show button enable .looking forward yours help.

$(document).ready(function(){         $('#agree').change(function(){        state = $('#agree').attr('value');        if ( state == 'on'){           $('#continue').removeattr('disabled');        }else if (state == '') {           $('#continue').attr('disabled','disabled');        }     }); }); 

you testing checkbox's value determine state. however, value not change (natively) when checked or unchecked. suggest referencing javascript's checked property, instead. see list of properties @ html input element.

in example below, i'm using this.checked reference status of checkbox has triggered "change" event. i'm using ternary operator set button's disabled property accordingly.

jquery('#agree').change(function() {    jquery('#continue').prop('disabled', this.checked ? false : true);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <label><input type="checkbox" id="agree" />click enable</label>  <button id="continue" type="button" disabled="disabled">a button</button>


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

post - imageshack API cURL -