Text field -> password field -> text field?

In order to have a password input field that has the defaul text "Enter Password:", I'm using the code below (found elsewhere in this forum).  But, how do you restore the default text / revert back to regular text field if the user clicks out of the box without entering anything?

So, it goes:

Text field : Default text = "Enter password"
User clicks in the text field and it becomes a password input box
User clicks out of the field without entering anything, and it goes back to a regular text field with the default "Enter password:" text

Thanks


<div id="pwTSpan">
<input id="pwx" type="text" onFocus="document.getElementById('pwTSpan').style.display='none'; document.getElementById('pwSpan').style.display=''; this.form.pw.focus()" value="password">
</div>
 
<div id="pwSpan" style="display:none"><input name="pw" id="pw" type="password" value=""></div>

Open in new window

n00b0101Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hujiCommented:
It is not possible, becasue in order to see if the user has left the password field blank, you should check the value of that field, and JavaScript doesn't allow you to check the value of password fields.
0
hujiCommented:
Oops! Ignore my last! Javasciprt "allows" checking the value. So all you need to do is something like:

<div id="pwSpan" style="display:none"><input name="pw" id="pw" type="password" value="" onBlur="if (document.getElementById('pw').value==''){ document.getElementById('pwSpan').style.display='none'; document.getElementById('pwTSpan').style.display=''; }"></div>

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hujiCommented:
This is the final version of the code which works on all browsers:

<div id="pwTSpan">
<input id="pwx" type="text" onFocus="document.getElementById('pwTSpan').style.display='none'; document.getElementById('pwSpan').style.display=''; document.getElementById('pw').focus()" value="password">
</div>
 
<div id="pwSpan" style="display:none"><input name="pw" id="pw" type="password" value="" onBlur="if (document.getElementById('pw').value==''){ document.getElementById('pwSpan').style.display='none'; document.getElementById('pwTSpan').style.display=''; }"></div>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.