Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enable or disable checkbox in html

Tags:

html

jsp

I want to enable or disable checkbox in table's row on basis of condition.

code -

<td><input type="checkbox" name="repriseCheckBox" disabled={checkStat == 1 ? true : false}/></td> 

if checkStat = 1, need to disable checkbox else keep it enable.

It's not working. It disabling all the checkboxes. Any suggestions ?

like image 777
anirudha Avatar asked Aug 16 '12 13:08

anirudha


People also ask

How do I enable and disable a checkbox?

Press the disable button and then the enable button. The checkbox doesn't get enabled. As the answers tell it is because the disabled attribute is a boolean attribute.

How do I disable a checkbox?

We can make a checkbox disabled in HTML using the disabled attribute. We assign the disabled attribute to an input to disable that input. We can also use the jQuery prop() method to change the disabled attribute of an input to true.

How do you activate a checkbox in HTML?

The <input type="checkbox"> defines a checkbox. The checkbox is shown as a square box that is ticked (checked) when activated. Checkboxes are used to let a user select one or more options of a limited number of choices. Tip: Always add the <label> tag for best accessibility practices!


1 Answers

If you specify the disabled attribute then the value you give it must be disabled. (In HTML 5 you may leave off everything except the attribute value. In HTML 4 you may leave off everything except the attribute name.)

If you do not want the control to be disabled then do not specify the attribute at all.

Disabled:

<input type="checkbox" disabled> <input type="checkbox" disabled="disabled"> 

Enabled:

<input type="checkbox"> 

Invalid (but usually error recovered to be treated as disabled):

<input type="checkbox" disabled="1"> <input type="checkbox" disabled="true"> <input type="checkbox" disabled="false"> 

So, without knowing your template language, I guess you are looking for:

<td><input type="checkbox" name="repriseCheckBox" {checkStat == 1 ? disabled : }/></td> 
like image 54
Quentin Avatar answered Sep 24 '22 10:09

Quentin