javascript - Disable input if checkbox is ticked on page load AND when it is clicked -


i've looked @ loads of questions describe how check weather check box checked or not none of them gives answer need. want check whether check box checked on page load , if is, disable input. need disabled input changed when box checked/uncheked after page load.

this have:

jquery(document).ready(function($) {     if ($('.is-repeat-event').prop('checked')) {       $('.event-date').prop('disabled', 'true' );     }     $('.is-repeat-event').change(function(){         var d = this.checked ? 'true' : 'false';         $('.event-date').prop('disabled', d );     }); }); 

either part on it's own works putting them doesn't work (the .change event has no effect on input).

that beacause property disabled need set boolean true/false values. can trigger event after binding see relevant changes in page load:

$('.is-repeat-event').change(function(){    $('.event-date').prop('disabled', this.checked ); }).change(); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -