4

I want to change the input type to password when I click on it. I tried this:

<input name="pin" id="cp_serv" type="text" class="pin_v" value="Insert PIN Please" onclick="this.value='';$(this).attr('type','password');"/>

I tried to use the jQuery function attr to change this on the click event, but nothing is happening.

Is this the right way to do it or is this possible?

5
  • Seems to work fine: jsfiddle.net/j08691/H24VP Commented Aug 30, 2013 at 18:13
  • 1
    Instead of a JavaScript workaround use the placeholder-attribute. Browser support. Commented Aug 30, 2013 at 18:15
  • @j08691 Did you try it in IE? If you read the question rink.attendant linked, it says that IE doesn't allow it. Commented Aug 30, 2013 at 18:15
  • People read the duplicate link... This wouldn't work on IE8 Commented Aug 30, 2013 at 18:18
  • The problem in firefox i can´t do works fine , no show dots of password when i go to do click Commented Aug 30, 2013 at 18:24

2 Answers 2

16

This will work

$('input').on('click', function () {
   $(this).attr('type', 'password'); 
});

jsfiddle

Update

For IE read accepted answer for this post.

Sign up to request clarification or add additional context in comments.

6 Comments

Did you test it in IE?
Please test this on IE 8
Might want to just limit it to the cp_serv input box or every input on the page will change. And also you might want to check out .prop().
I don't have IE. I am Mac user. Could you please test it if it works?
It doesn't. I was just being polite :)
|
-2

jquery.Attr should work the way that you want:

http://jsfiddle.net/7UA95/

UPDATE

This one when you click on it:

http://jsfiddle.net/7UA95/1/

1 Comment

According to the duplicate question, IE doesn't allow you to change input type.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.