views:

274

answers:

3

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

+4  A: 
$('#myElement').is(":checked")

Ignore the IE6 nonsense, and just use jQuery.

http://www.jquery.com

Stefan Kendall
I would, but I am using prototype, and I dont want to include another framework just to check a single thing.
Krishna Kant Sharma
This is not IE nonsense. The `checked` property of checkboxes in IE 6 works fine as a few simple tests would show. Throwing jQuery at it is like using a steamroller to juice a lemon.
Tim Down
No, it's not. One should not be bothered to learn what works and doesn't in IE6. If you have any issues whatsoever, I claim that library abstraction SHOULD be the first step, and if THAT fails, then you have issues.
Stefan Kendall
Dealing with forms in JavaScript is simple stuff that works absolutely fine in IE 6 without the need for burdening **the user** with the extra download and processing jQuery or any other general purpose library requires because you, the developer, couldn't be bothered to learn the most basic of browser scripting tasks.
Tim Down
You mean the basics of IE6. I hope no future developer should ever be burdened with such tasks. The problem here is NOT that I didn't bother, but it's inconvenient to test, shouldn't be necessary, and programming languages/rendering engines should just WORK. jQuery makes this possible.
Stefan Kendall
This problem almost certainly is an issue with IE's implementation of `document.getElementById` (see my answer for details). I've tested jQuery with it and it does appear to know about this IE behaviour and work round it, so I will concede you have a point on this one, as dealing with this kind of thing is a waste of development time. However, once armed with this knowledge, you still don't need jQuery.
Tim Down
A: 
Psytronic
+2  A: 

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.

Tim Down
I wish I could make a virus against IE
Krishna Kant Sharma
IE is the virus!
Psytronic