开发者

modify checkbox using javascript

开发者 https://www.devze.com 2023-02-06 00:22 出处:网络
I had declared 5 checkboxes with name and id attribute in a html: <input type=\"checkbox\" name=\"category\" value=\"One\" id=11>One<br/>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号