Hi Guys,I'm working on masking some input fields, for the credit card field requirement is that characters should be masked while you are typing in the field and also on focus out. So ofcourse I achieved that easily by converting the field to type password. But the next requirement is that when the user clicks back in the field (focus), it should should show the value but as soon as the user starts typing, the value should be masked. I've tried all sorts of things but I was finally stuck because of IE 8 , as it won't let me change the type. Does anyone have a solution that will work in all browsers including IE 8?

Thanks for your replies, this didn't work in IE8, I'm also using an older version of jQuery 1.4.2, right now I don't have the flexibility to update it for the application. So sorry guys but none of the above have worked for me so far

Thanks for all your help so far guys, if the above is true then below should work, but it doesn't . I have not even checked this in IE yet, only tested in chrome and it's not working. So what do you think I'm missing? There are no errors in the console but just absolutely nothing happens when I type in the filed, it just acts as text field.

I just got hold of a copy of IE8 to test on and my demo is rather broken

I couldn't test David's version as JSFiddle is equally as broken in IE8, but I'm sure that'll be what you're looking for.

If for some reason it doesn't work, I'm sure I could debug mine.

Yes, your solution does not work in IE, don't think it even does in IE9, haven't checked 10 or 11.I'm not sure what is wrong but I cannot get delegate to work, simple piece of code as below won't even work. Nothing triggers, I'm not sure what is going on, possible you can check David's solution on your Machine now that you have IE8? Appreciate the help!

Working off of davidfregoli's clever solution, you could do this in plain JS:

IE8 only runs JScript ands so only supports attachEvent and not addEventListener.

I already posted a link to a plain JavaScript version that does work even in IE5 back in post 4 of this thread.

JScript does not support changing the type attribute. It does support conditional comments so that you can use those to readily distinguish between browsers that run JavaScript and those that run JScript (IE9 slightly complicates things by supporting both).

omg sorry I thought I had copy/pasted the new code you provided but I was still using the old code. Now that I have the code updated it is somewhat working in IE 8, sometimes it has a weird behavior, the cursor jumps one character behind while you are typing, so messing up the input. In IE 9, it does not switch to password type at all while you are typing and also the cursor jumps back one character every time a character is typed in. I feel we're almost there! I'll keep looking into it, let me know if you any suggestions for this.