View Full Version : replaceNode() error in FF

01-15-2007, 07:00 PM
The script:

function toPassword(oInput) {
var newEl = document.createElement('input');
newEl.setAttribute('type', 'password');
newEl.setAttribute('name', 'pw');
newEl.setAttribute('id', 'pw');
newEl.setAttribute('value', '');
newEl.setAttribute('maxlength', '16');
toPassword.el = newEl;
return true;

( From This Thread (http://www.codingforums.com/showthread.php?t=22366&highlight=changing+input+type+property+password) )

Here is my form:

<form action="login.php" method="post" id="login">
<input type="text" name="un" id="un" value="username" maxlength="45" onFocus="if(this.value=='username'){this.value='';}" />
<input type="text" name="pw" id="pw" value="password" maxlength="16" onFocus="if(this.value=='password'){this.value=''; toPassword(this);}" />
<input type="image" src="images/layout/login_submit.gif" name="submit" id="submit" value="LOGIN" />

When i run this in IE, it works great. In FF, i get an error: oInput.replaceNode is not a function.

For a bit of history on this, I tried simply doing a [object].type='password'. This works in Firefox, but it prevented by security measures in IE. So for those who might suggest that, that won't work here.

How can i get rid of the function does not exist error?
Thank you.

01-15-2007, 07:18 PM
Well, one way would be to use a function that exists instead :)

replaceNode is an iew proprietary thing. The DOM way of doing it is:
oldChild.parentNode.replaceChild(newChild,oldChild)And documentation can be found here: Node.prototype.repaceChild (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-785887307)

01-15-2007, 07:20 PM
Thank you very much.