Skip to content
Advertisement

how to disable a check box using java script conditionally

i have 3 check boxes in 3 different pages,i want to check one check box at time means at first all 3 are unchecked and if i checked one check box remaining 2 check boxes should be disable.

each check box value i am storing in 3 different text file using array in the form of 1’s and 0’s. now for one page i am reading check box values and based condition trying to disable check box but its not working.

I have Tried this

check box html code:

JavaScript

java script:

JavaScript

cb1.disabled = true; for me its not working i kept alert statements above and below it ,only above one is displayed

Please help me how to set disabled property, thanks

Advertisement

Answer

You need to check input1.value == "", not simply input1 == ""

You also need to fire your method originally, and also run it every time your select lists change value.

Give the function a name

JavaScript

Add event listeners

JavaScript

Finally, you can reduce your if() statement to a simple assignment…

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement