I try to do a form with the information in the same input. It works fine in all the inputs but in the password it would be better if it could change to points when the user introduces the password. I want it to be type text and change to type password ONLY when the user introduces the password. The problem is in the last line of code:
I have it life here: http://jsfiddle.net/Nt9gx/
<form>
<input type="text" name="name" value="name"
onfocus="if (this.value=='name') this.value = '';"
onblur="if (this.value=='') this.value = 'name';"
/>
<input type="text" name="password" value="password"
onfocus="if (this.value=='password') this.value = '' type = password;"
onblur="if (this.value=='') this.value = 'password';"
"if (this.value!=''|| 'password') type = password ;"
/>
</form>
Use the HTML5 placeholder
To get the job done, you should simply use the HTML5
placeholder-attribute, like this:As this will:
By the way:
onbluron the last input, this should occur only oncethe last line is syntactically wrong, as you need to escape the word password in(question was updated)'(single quotes) instead of"(double quotes)passwordin|| password)type="password"for input fields that handle, well, passwords, as the input will be “invisible”Note:
If you still want to use JavaScript, you have to change the input from
type="text"totype="password"within the focus and blur events by simply updating thetype-attribute.This is how you can do it:
Demo: http://jsfiddle.net/2Ps8N/