I had declared 5 checkboxes with name and id attribute in a html:
<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/>
开发者_开发知识库After declaration, I want to run a javascript that would enable the checkbox1 using that checkbox id.
Let me know to clarify something.
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;
try
document.myform.box1.checked = true;
or
document.getElementById('myid').checked = true;
see an full example : http://www.rgagnon.com/jsdetails/js-0007.html
document.getElementById('checkbox1').checked = true;
To check a check box you can use :
document.getElementById("Checkbox_ID").checked = true;
And to uncheck a check box you can use :
document.getElementById("Checkbox_ID").checked = false;
And for more info visit this page
精彩评论