Skip to content Skip to sidebar Skip to footer

Change Text Box Text If Checkbox Is Checked

I want to change text box text depending if checkbox is checked or not. So if the user checks the checkbox, the text box shows some text and if the user unchecked the checkbox, it

Solution 1:

Try binding to the click event:

$('input[type=checkbox]').click(function () {
    if ($('input[type=checkbox]').is(':checked')) {
        $('#txt').val('checked');
    }
    else{
        $('#txt').val('unchecked');
    }
});

Solution 2:

It should be like this

$(document).ready(function () {

    $('input[type=checkbox]').click(function(){
       if ($('input[type=checkbox]').is(':checked')) {
         $('#txt').val('checked');
       }
       else{
         $('#txt').val('unchecked');
       }
    });

});

check the Demo

Post a Comment for "Change Text Box Text If Checkbox Is Checked"