Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a input field and on clicking that checkbox it enables and disables the text box.

By default, the box is checked.

I have the following code. Once i uncheck that box, the display is disabled. However, when i check it again, it still remains disabled.

Can someone please tell me where i am doing it wrong.


Any help is appreciated.

Thank you.

What I have tried:

<input type="checkbox" class="show-check" checked value="1" id="DisplayOnClick">


document.getElementById("DisplayOnClick").onclick = function(){
        if(document.getElementById("DisplayOnClick").checked){
            document.getElementById("myFieldset").style.display = "block";
           
        } else {       
            document.getElementById("myFieldset").disabled = !this.checked;          
        }
    }


$(function () {

        $("#DisplayOnClick").click(function () {
            if ($(this).is("checked")){
                $("#myFieldset").show();
            }else {
                $("#myFieldset").hide();
            }
        });
    });
Posted
Updated 7-Dec-22 4:24am

1st go to your textbox properties and find “Enabled” and set it to False
Then double click on your checkbox from form or anywhere and then paste this code:

Private Sub CheckBox1_Click()
If CheckBox1=True Then
TextBox1.Enabled=True
ElseIf CheckBox2 = False Then
TextBox1.Value=“”
TextBox1.Enabled= False
End If
End Sub
 
Share this answer
 
Just using the following worked for me.

document.getElementById("DisplayOnClick").onclick = function(){
 document.getElementById("myFieldset").disabled = !this.checked;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900