Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  86] [ 4]  / answers: 1 / hits: 43512  / 14 Years ago, tue, january 25, 2011, 12:00:00

I want to have a password field which says Password in it before a user enters their password (so they know what the field is)



I'd rather just use Javascript, importing jQuery for this alone seems wasteful, but I have no idea how to. The images explain quite clearly:



What it looks like:



enter



What I want it to look like:



enter



It's only a very simple website and the most basic of logins (has no validation etc)



Any ideas?



<input id=username name=username class=input_text type=text value=Username  />
<input id=password name=password class=input_text type=password value=Password />

More From » html

 Answers
5

Change your password input to be a simple input type text. Then, with JavaScript (or JQuery) on focus event, change it to be a input type password.



Here is a little untested sample with plain JavaScript (no JQUERY):



<html>
<head>
<script type=text/javascript>
function makeItPassword()
{
document.getElementById(passcontainer)
.innerHTML = <input id=password name=password type=password/>;
document.getElementById(password).focus();
}
</script>
</head>
<body>
<form>
<span id=passcontainer>
<input onfocus=return makeItPassword() name=password type=text value=Type Password />
</span>
</form>
</body>
</html>

[#94058] Monday, January 24, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleyk

Total Points: 730
Total Questions: 99
Total Answers: 99

Location: South Georgia
Member since Fri, Nov 13, 2020
4 Years ago
;