/    Sign up×
Community /Pin to ProfileBookmark

Checkbox won’t check in IE? :(

I’m trying to dynamically create a checkbox element with the checked status being true however it never works in IE, I’ve tried everything I can think of. The code works in firefox but IE never checks the box, when I do an alert it says its checked but it does not render the check.

var chk_box = document.createElement(“input”);
chk_box.checked = true;
chk_box.setAttribute (“type”,”checkbox”);
chk_box.setAttribute (“name”,”vulns”+i);
chk_box.setAttribute (“value”,”1″);
item.appendChild(chk_box);

I’ve also tried:
chk_box.setAttribute (“checked”,true);

and
item.lastChild.checked = true;

none seem to work in IE, any tips? thanks!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JMay 31.2005 — Could you not put

document.forms["formName"]["elementName"].checked=true

after you have appended the checkbox
Copy linkTweet thisAlerts:
@cobain_attacksauthorMay 31.2005 — I'm actually appending it to a documentFragment then after my loop is finished I append the documentfragment to the dom node, I've tried pretty much everything at this point ?
Copy linkTweet thisAlerts:
@Mr_JMay 31.2005 — I'll point out that I do not have a great deal of experience when it comes to DOM, sorry, but here's something else I tried where the checkbox did load checked in IE.

I appended to the body and had to take out the variable i only to get it to work for my testing

[code=php]<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>

<script>
<!--
var chk_box = document.createElement("input");
chk_box.checked = true;
chk_box.setAttribute ("type","checkbox");
chk_box.setAttribute ("name","vulns");

chk_box.setAttribute ("id","vulns");

chk_box.setAttribute ("value","1");

document.getElementsByTagName("BODY").item(0).appendChild(chk_box);

document.getElementById("vulns").checked=true

//-->
</script>
</BODY>
</HTML>[/code]
Copy linkTweet thisAlerts:
@felgallMay 31.2005 — You can only update the style after the node has been added to the page with Internet Explorer.
×

Success!

Help @cobain_attacks spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...