i using following javascript hide form if user clicks on checkbox.
i trying code run on page load not able work out how this. can help?
$('#no_cage').change(function(){ if (this.checked) { $('#cage_details').fadeout(); } else { $('#cage_details').fadein(); } });
html:
<input name="no_cage" id="no_cage" type="checkbox" value="1" <?php echo $checked; ?>><label for="no_cage">check if not required</label> <div id="cage_details"> <form> ... </form> </div>
this works fine when user clicks on checkbox. not when pulls db , checkbox selected on page load.
just add code inside document ready handler. trigger change event handler without needing change...
$('#no_cage').trigger("change");
alternatively, trigger event declare it...
$('#no_cage').change(function(){ if (this.checked) { $('#cage_details').fadeout(); } else { $('#cage_details').fadein(); } }).trigger("change");
that add event handler , execute it, in order set form correct state when document has loaded.
Comments
Post a Comment