IE not detecting onChange properly - can I compensate?

C

Csaba Gabor

If I detect an empty textbox, I fill it with a value ('Dad').
If I do this twice, the second time around IE 6 fails to notice
that I've cleared the textbox again, thus leaving the textbox
cleared. Is there a recommended workaround?
Opera 7.23 is detecting the second deletion fine.

Thanks,
Csaba Gabor

The page snippet below illustrates what I mean:

<SCRIPT type='text/javascript'>
function changeNoted(inputElem) {
if (!inputElem.value) inputElem.value = 'Dad';
}
</SCRIPT><FORM>
<INPUT type='text' name='foo' value='Mom' onChange='changeNoted(this)'>
</FORM>
 
Y

Yann-Erwan Perio

Csaba said:
If I detect an empty textbox, I fill it with a value ('Dad').
If I do this twice, the second time around IE 6 fails to notice
<INPUT type='text' name='foo' value='Mom' onChange='changeNoted(this)'>

IE sucks. Use "onblur" instead of "onchange".


Regards,
Yep.
 
C

Csaba Gabor

Ahem. The following compensates for the mentioned Microsoft bug.
Evidently, clones are not quite identical, ha ha.

<FORM>
<INPUT type='text' name='foo' value='Mom' onChange='changeNoted(this)'>
</FORM>
<SCRIPT type='text/javascript'>
function changeNoted(inputElem) {
if (!inputElem.value) {
inputElem.value = 'Dad'; // all we should need, but for IE...
var cloned = inputElem.cloneNode(true);
if (cloned.value=='Dad') // Opera clone is fake (.value is 'Mom')
inputElem.parentNode.replaceChild(cloned, inputElem);
}
}
</SCRIPT>

Csaba Gabor
only tested on IE 6 and Opera 7.23
Note: this method introduces orphan nodes into the DOM
 

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

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top