Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make password textbox value visible when hover an icon

Good day all,

I have a form that has a password field:

<input type="password" name="password" size="30" /> 

Naturally, the input text will be replaced by (*).

So if the user typed 123 the box will show ***.

Up to here, it is straight forward, but...

Now, I wanna add a small icon next to the password box so when the user hover over this icon, he can see what he has entered so far.

So, while hovering, the box will show 123 and when the user leaves the icon the box should show *** again.

Is there any way to do this with JavaScript? Also, I am using HTML and PHP.

EDIT:

It really doesn't need to be an icon, it could be a checkbox or a button... AND if it could be done in CSS, I would really appreciate to know how

P.S. I've googled and search the stackoverflow but with no luck

like image 922
SULTAN Avatar asked Mar 18 '14 12:03

SULTAN


People also ask

How do I password protect a textbox in HTML?

The <input type="password"> defines a password field (characters are masked). Note: Any forms involving sensitive information like passwords should be served over HTTPS. Tip: Always add the <label> tag for best accessibility practices!

How do I find the password for a text box?

Right-click the password field and click Inspect Element. A gray bar will appear with the password field highlighted. Press Alt+M or click on the icon shown below to open the Markup Panel. It will show you the code for the password field.


1 Answers

You will need to get the textbox via javascript when moving the mouse over it and change its type to text. And when moving it out, you will want to change it back to password. No chance of doing this in pure CSS.

HTML:

<input type="password" name="password" id="myPassword" size="30" /> <img src="theicon" onmouseover="mouseoverPass();" onmouseout="mouseoutPass();" /> 

JS:

function mouseoverPass(obj) {   var obj = document.getElementById('myPassword');   obj.type = "text"; } function mouseoutPass(obj) {   var obj = document.getElementById('myPassword');   obj.type = "password"; } 
like image 160
Merlin Denker Avatar answered Oct 14 '22 15:10

Merlin Denker