Placeholder works for text, but not in password field in IE / Firefox using this javascript

Js file

//Modified from http://www.beyondstandards.com/archives/input-placeholders/
function activatePlaceholders()
{
    var detect = navigator.userAgent.toLowerCase(); 
    if (detect.indexOf("safari") > 0) return false;
    var inputs = document.getElementsByTagName("input");
    for (var i=0;i<inputs.length;i++)
    {
        if (inputs[i].getAttribute("type") == "text")
        {
            var placeholder = inputs[i].getAttribute("placeholder");
            if (placeholder.length > 0)
            {
                inputs[i].value = placeholder;
                inputs[i].onclick = function()
                {
                    if (this.value == this.getAttribute("placeholder"))
                    {
                        this.value = "";
                    }
                    return false;
                }
                inputs[i].onblur = function()
                {
                    if (this.value.length < 1)
                    {
                        this.value = this.getAttribute("placeholder");
                    }
                }
            }
        }
        else if (inputs[i].getAttribute("type") == "password")
        {
            var placeholder = inputs[i].getAttribute("placeholder");
            if (placeholder.length > 0)
            {
                inputs[i].value = placeholder;
                inputs[i].onclick = function()
                {
                    if (this.value == this.getAttribute("placeholder"))
                    {
                        this.value = "";
                    }
                    return false;
                }
                inputs[i].onblur = function()
                {
                    if (this.value.length < 1)
                    {
                        this.value = this.getAttribute("placeholder");
                    }
                }
            }
        }
    }
}
window.onload = function()
{
    activatePlaceholders();
}

Html part

<form name="input" action="login.php" method="post">
        <table width="*" border="0">
        <tr>
        <td align="left"><input type="text" name="username" placeholder="Username" />&nbsp;<input type="password" name="pass" placeholder="Password" /><input type="submit" value="Login" /></td>
        </tr>
        <tr>
        <td colspan="2" align="right">Stay logged in:&nbsp;<input type="checkbox" name="remember" value="1">&nbsp;&nbsp;Sign Up | Forgot Password&nbsp;&nbsp;&nbsp;</td>
        </tr>
        </table>
        </form>

This works for an input field. Not working for password. He wants to display the text of the owner of the place in the password. I want the user password to start, but not the owner of the place. Not sure how to fix this, so it works in IE and Firefox.

0
source share
1 answer
var passwords = document.getElementsByTagName("password");

Must be:

var passwords = document.getElementsByTagName("input");

How is he <input type="password">not <password...>. However, I do not think that this will help you in this case, because when you set the password value, all you see is black dots / asterisks.

+2
source

All Articles