Changing the <input> type in IE with JavaScript
Posted
by MrEnder
on Stack Overflow
See other posts from Stack Overflow
or by MrEnder
Published on 2010-04-02T11:33:59Z
Indexed on
2010/04/04
21:53 UTC
Read the original article
Hit count: 286
The line
<input type="text" name="passwordLogin" value="Password" onfocus="if(this.value=='Password'){this.value=''; this.type='password'};" onblur="if(this.value==''){this.value='Password'; this.type='text'};" size="25" />
works in all web browsers except IE... How can I fix it for IE?
Ok made some changes to still have an error
I want it to work like this like here
<input type="text" name="usernameLogin" value="Email" onfocus="if(this.value=='Email'){this.value=''};" onblur="if(this.value==''){this.value='Email'};" size="25" />
if I dont enter anything it will put the value back
So I tried this
<td colspan="2" id="passwordLoginTd">
<input id="passwordLoginInput1" type="text" name="passwordLogin" value="Password" onfocus="passwordFocus()" size="25" />
<input id="passwordLoginInput2" style="display: none;" type="password" name="passwordLogin" value="" onblur="passwordBlur()" size="25" />
</td>
<script type="text/javascript">
//<![CDATA[
passwordElement1 = document.getElementById('passwordLoginInput1');
passwordElement2 = document.getElementById('passwordLoginInput2');
function passwordFocus() {
passwordElement1.style.display = "none";
passwordElement2.style.display = "inline";
passwordElement2.focus();
}
function passwordBlur() {
if(passwordElement2.value=='') {
passwordElement2.style.display = "none";
passwordElement1.style.display = "inline";
passwordElement1.focus();
}
}
//]]>
</script>
as you can see the blur does not work =[
ok finally got it thanks to the help needed to remove
passwordElement1.focus();
© Stack Overflow or respective owner