This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan
<p>I have been having a problem in IE7 and Internet Explorer 6, by where if you dynamically create a checkbox, set it to checked = true and then add it in to the HTML document, it loses it's checked status.<p />var newCheck = document.createElement('<input name=relatedSearchesChk>');newCheck.type = "checkbox"; newCheck.onclick = updateCheckStatus;//Function to Call when clickednewCheck.relatedUrl = currSearch.Query;//Expando StringnewCheck.relatedObject = currSearch; //Expand ObjectnewCheck.checked = isChecked; //DOESN't WORK. isChecked is just a local Booelan Variable.tagCell1.appendChild(newCheck);<p />The closest related problem on the web that I found was this thread: <a href="http://forum.java.sun.com/thread.jspa?threadID=628633&messageID=3810937">Java Forums - Creating a checked Checkbox through javascript</a>. The solution in this thread works.<p />However I found another solution. Update the checked status after it has been added to the document. I have no idea why it works like this but it does work.<p />var newCheck = document.createElement(<input name=relatedSearchesChk>');newCheck.type = "checkbox"; newCheck.onclick = updateCheckStatus;//Function to Call when clickednewCheck.relatedUrl = currSearch.Query;//Expando StringnewCheck.relatedObject = currSearch; //Expand ObjecttagCell1.appendChild(newCheck);newCheck.checked = isChecked; //WORKS<p />If you know why this happens I would love to know: <a href="mailto:%20paul.kinlan@gmail.com">paul.kinlan@gmail.com</a><p /></p>
This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan