Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IE not detecting onChange properly - can I compensate?

97 views
Skip to first unread message

Csaba Gabor

unread,
Apr 15, 2004, 4:14:35 PM4/15/04
to
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>


Yann-Erwan Perio

unread,
Apr 15, 2004, 5:50:10 PM4/15/04
to
Csaba Gabor wrote:

> 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.

mscir

unread,
Apr 15, 2004, 5:59:48 PM4/15/04
to
Csaba Gabor wrote:

Weird Bug. How about this:

<INPUT type='text' name='foo1' value='Mom' onBlur='changeNoted(this)'>

Mike

Csaba Gabor

unread,
Apr 15, 2004, 6:00:19 PM4/15/04
to
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


0 new messages