i'm trying code text field disabled when check box 'checked'.
below code i'm using. have no bloody idea why it's not working. suspect may wordpress' fault i'm new javascript i'm hoping it's that.
<script type="text/javascript"> $('input[name=addresscheck]').change(function(){ if($(this).is(':checked')) { $("#dbltext").removeattr('disabled'); } else{ $("#dbltext").attr('disabled','disabled'); } }); </script> <input name="addresscheck" type="checkbox" id="addresscheck" /><br /> <input type="text" id="dbltext" disabled/>
the script runs before browser sees rest of page, element never found, nothing gets bound
try
$(document).ready(init); // or document.addeventlistener('domcontentloaded', init); function init(){ $('input[name=addresscheck]').change(function(){ if($(this).is(':checked')) { $("#dbltext").removeattr('disabled'); } else{ $("#dbltext").attr('disabled','disabled'); } }); } or move script end of body
Comments
Post a Comment