javascriptcheckbox

How to enable a checkbox with Javascript?


I have 5 checkboxes with name and id attribute:

<input type="checkbox" name="category" value="One" id=11>One<br/> 
<input type="checkbox" name="category" value="Two" id=12>Two<br/> 
<input type="checkbox" name="category" value="Three" id=13>Three<br/> 
<input type="checkbox" name="category" value="Four" id=14>Four<br/>

I want Javascript code to enable checkbox1 using that checkbox id.


Solution

  • Try this for checking the checkbox:

    document.getElementById(<id of first checkbox>).checked = true;
    

    Try this for enabling the checkbox:

    document.getElementById(<id of first checkbox>).disabled = false;