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:
What I want it to look like:
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" />
I had another idea to deal with this problem and you will need no Javascript:
Or you can also do it like this:
I do not know the difference between this possibilities. Another thing you could change is to write instead of
onclick=.......
onfocus=.....
I don't know the difference here, too.
But I hope I could help you. PS: Sorry because of my bad English I'm German.
A simple solution:
Change your
password
input to be a simple input typetext
. Then, with JavaScript (or JQuery) on focus event, change it to be a input typepassword
.Here is a little untested sample with plain JavaScript (no JQUERY):
If you're using HTML5 then you should use the placeholder attribute.
If you're using HTML4 you can create a fake password field.
Add the following code to your javascript:
Change the input for the password to:
What this does it it makes the input element a 'password' and the value is updated so that it is hidden. If you would like for the value="Password" to be visible if the field is left empty then add the following javascript function:
And add the following to your password input: