I am frustrated with the most idiotic browser of all time, for which, Bill Gates must be hanged I think.
I just want to check whether a checkbox is checked or not.
Somehow
cbox.checked
property is always false. What other thing I can do. I saw all the other similar questions, but nothing is working with this stupid IE.
EDIT
I forgot to mention something that may be relevent. Html is like:
<input type='hidden' name='terms' value='0' />
<input type='checkbox' name='terms' id='terms' value='1' />
Hidden field is attached with it, because I am using Zend Form, and it always attaches a hidden field with every checkbox.
I am using protoype.js thats why I cannot use jQuery. I am checking that its check or not, in onsubmit event of the form. I guess somehow hidden field with the same name is tripping IE6
I am frustrated with the most idiotic browser of all time, for which, Bill Gates must be hanged I think.
I just want to check whether a checkbox is checked or not.
Somehow
cbox.checked
property is always false. What other thing I can do. I saw all the other similar questions, but nothing is working with this stupid IE.
EDIT
I forgot to mention something that may be relevent. Html is like:
<input type='hidden' name='terms' value='0' />
<input type='checkbox' name='terms' id='terms' value='1' />
Hidden field is attached with it, because I am using Zend Form, and it always attaches a hidden field with every checkbox.
I am using protoype.js thats why I cannot use jQuery. I am checking that its check or not, in onsubmit event of the form. I guess somehow hidden field with the same name is tripping IE6
Share Improve this question edited Oct 16, 2009 at 7:38 Krishna Kant Sharma asked Oct 15, 2009 at 22:54 Krishna Kant SharmaKrishna Kant Sharma 1,5871 gold badge12 silver badges19 bronze badges 8- Are you checking the correct element? Try adding a style to it to make sure. Also when are you checking? Show the code for further help. – Ollie Saunders Commented Oct 15, 2009 at 23:00
- How are you making it "checked" in the first place? – kangax Commented Oct 15, 2009 at 23:01
- Yes I am checking the correct element (id is correct). Also, when I alert(cbox) it prints htmlelement. In the above description, cbox is the variable, which holds reference to the checkbox element. – Krishna Kant Sharma Commented Oct 15, 2009 at 23:11
- @kangax I am making it checked, by clicking on it. – Krishna Kant Sharma Commented Oct 15, 2009 at 23:15
- Most idiotic browser of all time? Sounds like you never had to work with Netscape 4... – Tim Down Commented Oct 15, 2009 at 23:23
3 Answers
Reset to default 5$('#myElement').is(":checked")
Ignore the IE6 nonsense, and just use jQuery.
http://www.jquery.
Now you've posted your HTML your problem is clear: you've got two form elements with name 'terms' and IE 6 is finding the wrong one, because it has a broken implementation of document.getElementById
that uses the name
attribute of form elements as the id. The solution is to ensure you don't have form elements with the same name as any element you wish to refer to by id, and avoid using the same name for unrelated form elements.
Note that the problem will also exist in IE 7, according to this blog post.
I have to agree, IE 6 is a pain sometimes, and unfortunately we have to cater to that minority who still haven't upgraded. But this works for me within IE6
EDIT: After reading Tims Post have updated function reflect this. Tested and works in IE6.
function chk(){ inps = document.getElementsByTagName("INPUT"); for(i = 0; i < inps.length; i++){ if(inps[i].name == "terms" && inps[i].type == "checkbox"){ alert(inps[i].checked); } } }