Skip to content Skip to sidebar Skip to footer

How To Disable A Textbox If A Checkbox Is Checked Using Jquery?

I want to disable a textbox if a user unchecks a checkbox and change the background colour of textbox. If the user checks the checkbox then that textbox should be editable and chan

Solution 1:

Here is JS the code

$(".ba").click(function () {
    if ($(".ba").is(":checked")) {
        $(".tex")
            .removeAttr("disabled")
            .css("background-color", "white");
    }
    else {
        $(".tex")
            .attr("disabled", "disabled")
            .css("background-color", "red");
    }
});

I recommend you to check out Jquery API. It's a fun read :)

Solution 2:

$(document).ready(function(){
$(".ba").click(function() {
if ($('#check_id').is(":checked"))
{
  $(".tex").css("background-color","#CCCCCC");
}
else
{
   $(".tex").css("background-color","#DDDDDD");
}
});
});

Solution 3:

Try like

$(".ba").on('click',function() {
   if($(this).is(':checked'))
       $(".tex").css("background-color","#CCCCCC");
   else$('.tex').prop('disabled', false);
})'

Post a Comment for "How To Disable A Textbox If A Checkbox Is Checked Using Jquery?"