0

This is the code I have already. When the box is inactive it displays the text"Password". I would like when the box is selected it removes the "Password" text and displays the users input as dots like a password field.

<div class="custom"><input type="text" class="custom" size="12" value="Password" onfocus="if(this.value == 'Password') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Password'; }"/></div>

3 Answers 3

2

You can change the type via JS the same way you've changed the value:

<input type="text" class="custom" size="12" value="Password" onfocus="if(this.value == 'Password') { this.type = 'password'; this.value = ''; }" onblur="if(this.value == '') { this.type = 'text'; this.value = 'Password'; }"/>
Sign up to request clarification or add additional context in comments.

Comments

0

If i understand correctly, you're just looking for:

this.type = 'password'

and conversely:

this.type = 'text'

Comments

0

You should start by setting the type of the input to 'password'. If you want to display a label for the field in the value, i would recommend using the JQuery watermark. It effectively does what i believe you are attempting to code out, but won't ever submit the word 'Password' as the value of the form field.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.