Click to See Complete Forum and Search --> : removeAttribute and removeNamedItem


Alsvha
August 15th, 2006, 09:51 AM
Greetings all.

I have some difficulties - or rather in my view oddities - in Internet Explorer and some sutff I try to make.

I have an input field (<input ....>) which have a onBlur call to a function.
If there is text in the input field I want this function to do some stuff, and then remove the onBlur call from the input field, so it only gets called once.

I first tried to do this with
myNode.attributes.removeNamedItem('onblur');
which works wonders in FireFox.
Supposedly this should also work in IE 6+, but it doesn't work in my IE version 6.

Then I tried myNode.removeAttribue('onblur'); which again - works in FireFox, but not in my IE 6. It even returns "true" in IE, indicating it successfully removed that attribute.

The result is that in IE I can call onBlur multiple times, eventhough I supposedly have removed the onBlur.


Have anybody else experienced this problem, and if so - found a workaround?

PeejAvery
August 15th, 2006, 01:02 PM
Could you post your code so that we can understand a little better?

Alsvha
August 16th, 2006, 02:52 AM
Sure thing:


(HTML)
<input type="text" id="bullet_0" name="bullet_0" value="" onBlur="addNewBullet(this);">


(JavaScript)
function addNewBullet(inNode)
{

if (inNode.value != '')
{
//inNode.attributes.removeNamedItem('onblur'); //First try
//inNode.removeAttribute('onblur'); //Second try.

//does some work here, for instance adds a new "bullet" input field.

}
else
{
//do work - snipped because it isn't relevant.
}
}


Irregardless of which of the two methods of removing "onblur" I use (removeNamedItem and removeAttribute), it doesn't work in my version of IE (6.0) and it keeps calling the function onblur from the "bullet_0" input field. In FireFox it only calls the onblur from the field once if it is being removed.

There are other alternatives I can use (such as checking if the current bullet is the last one and only then add another bullet etc) but it annoys me that this function seemingly doesn't work as I belive it should. But I can't see where I did wrong.