input checkbox onchange not working on IE7

D

David Mark

I am finding that <input type="checkbox" onchange="alert('test')"></input>
does not seem to work properly on IE7.

Use the click event with checkboxes. I think you will find that in
some browsers the change event fires only after the input loses focus.
 
A

Aaron Gray

David Mark said:
Use the click event with checkboxes. I think you will find that in
some browsers the change event fires only after the input loses focus.

Okay great 'onclick' works but how do Iget the checkbox'es value ?

<input type="checkbox" onchange="alert('test' + this.value)"></input>

Is always giving 'on'.

Thanks,

Aaron
 
X

xdevel1999

Okay great 'onclick' works but how do Iget the checkbox'es value ?

    <input type="checkbox" onchange="alert('test' + this.value)"></input>

Is always giving 'on'.

Thanks,

Aaron

simply put a value attribute on it


<input type="checkbox" value ="some_value" onclick="alert('test' +
this.value)"></input>

Bye
 
D

David Mark

Okay great 'onclick' works but how do Iget the checkbox'es value ?

    <input type="checkbox" onchange="alert('test' + this.value)"></input>

Is always giving 'on'.

Perhaps you meant onclick above? Also, the checked property is likely
what you are after. Do you really care about the value?
 
D

David Mark

Yes, sorry :)


Ah, got that :)


No.

Thanks alot David,

No problem. One caveat though. It seems to me that there is at least
one old version of Mac IE that will not work as expected. My memory
is fuzzy on this though. I remember consulting on a project a few
years ago that did something like this:

function mycheckboxclick() {
if (isMacIE) {
someglobalflag = this.checked;
} else {
someglobalflag = !this.checked;
}
}

This is madness of course (first thing I did was change the global
flag to a function that returned the present value of the checked
property.) The "reasoning" for the above logic was that a unit test
failed in Mac IE and this hack "fixed" it. This is the same brain-
dead methodology used by Prototype, jQuery, etc. You can probably
imagine my ultimate recommendation (throw the bums out.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top