admin管理员组文章数量:1355592
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.
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.
Share Improve this question edited Jul 1, 2024 at 8:25 Rob Bednark 28.3k27 gold badges88 silver badges130 bronze badges asked Jan 19, 2011 at 8:21 AnkitAnkit 2,2564 gold badges34 silver badges54 bronze badges 6- enable how? are they initially disabled? – amosrivera Commented Jan 19, 2011 at 8:25
- <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/> <script type="text/javascript">/*JS Code to enable the Checkbox 1*/ </script> – Ankit Commented Jan 19, 2011 at 8:28
-
If you are generating the code on the server side (or even if it is static code), you know you can make a checkbox be ticked by default by adding
checked="checked"
as attribute? – Felix Kling Commented Jan 19, 2011 at 8:29 - I agree but I want to enable the checkbox after their declaration through javascript. – Ankit Commented Jan 19, 2011 at 8:32
- @ankitjava: So you are creating them with JS. You did not say that ;) (at least not that it was clear to me :D) – Felix Kling Commented Jan 19, 2011 at 8:34
4 Answers
Reset to default 5Try 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./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
本文标签: How to enable a checkbox with JavascriptStack Overflow
版权声明:本文标题:How to enable a checkbox with Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744045262a2581403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论