The browser compatibility issues continue. For some time there has been a problem dynamically changing an input element from text to password (and vice-versa). In most browsers (Chrome, FireFox included) this is a very simple task:
var elem = document.getElementById('myInputBox');
elem.type = 'password';
In *uhem* Internet Explorer (IE) this will throw an exception, as changing the type attribute directly is not possible.
The solution I have come up with is far from foolproof so use it at your own risk. It only has basic error checking and has only been tested on PC (IE8, Chrome5, FireFox3).
It works by creating a new input element, setting the 'type' attribute, and then copying across the name, id, value and style attributes from the original element. It then uses teh DOM to completely replace the old element with the new one.
Note that it does not copy ALL attributes, so if there is anything you want to keep from the old element to the new one, add it to the function manually. In my case I ensure that onfocus and onblur are retained, for example, and you may also want to keep onclick or other events.
function invChangeInputType( elem, newType ){
if (elem.type==newType) return elem;
try{
elem.type=newType;
}catch(e){
if (document.createElement && elem.replaceNode){
var onFocus = elem.onfocus;
var onBlur = elem.onblur;
elem.onfocus = null;
elem.onblur = null;
var newElem = document.createElement("input");
newElem.type = newType;
newElem.name = elem.name;
newElem.id = elem.id;
newElem.value = elem.value;
newElem.className = elem.className;
for(var prop in elem.style){
newElem.style.setAttribute( prop, elem.style.getAttribute( prop ) );
}
elem.replaceNode(newElem);
newElem.onblur = onBlur;
newElem.onfocus = onFocus;
return newElem;
}
}
return elem;
}
var elem = document.getElementById('myInputBox');
elem = changeInputType(elem,'password');
www.juicycouture-uk.co.uk/juicy-couture-free-style-velour-black-handbag.html
We cannot change anything unless we accept it, Condemnation does not liberate it, it oppresses.
The code works really very well. Thanks for posting it. It helped me solve my problem. keep up the good work.
callprobest mosquito post
I want the Box to say the word "Password" but as you click it and start typing you password is not shown
...discount rimadyl for dogs
I am very excited that I have found your post because I have been searching for some information about it for almost three hours. You have helped me a lot and reading this your article I have found much new and useful information about this subject.schuttingen plaatsen
This looks totally ideal. All these tinny details are produced with lot of background knowledge. I like it a lot. This was a valuable post and I think it is rather straightforward to see from the other comments at the same time that this post is nicely written and valuable.haarspeldjes
I got the similar error where the letters in the password field was displayed in Asteric symbol whereas in the password field the letters were displayed clearly.The codes metioned above really works with little modification.
red cuff links
I really like the work that has gone into making the post. I will be sure to tell my blog buddies about your content.You've got so much to say and know so much about the subject that I think you should just teach a class about it. Pain On Top Of Foot
Thanks for code it works fine
It is a shame there is not an easy "perfect" solution
Motorcycle accident attorney California
Superb website you have here but I was curious if you knew of any user discussion forums that cover the same topics talked about in this article? I'd really love to be a part of online community where I can get opinions from other experienced people that share the same interest. If you have any recommendations, please let me know. Thank you!
GE PP945BMBB
You have given a worth necessary knowledge with us...keep giving such knowledge to us...Carson City Nevada DUI Attorney
Simply great work. I got the similar error where the letters in the password field was displayed in Asteric symbol whereas in the password field the letters were displayed clearly. does dermatend work
Simply great work. I got the similar error where the letters in the password
The code you have provided is for javascript,can you give something like that in PHP,i would be grateful..mole removal home remedy
Interesting post and thanks for sharing. Some things in here I have not thought about before.Thanks for making such a cool post which is really very well written. Will be referring a lot of friends about this. Keep blogging.redstone
I really like your way of expressing the opinions and sharing the information. It is good to move as chance bring new things in life, paves the way for advancement, etc. mcse exams // mcitp training // pmp exam // a+ practice test // cisco ccnp // mcts certification // Microsoft certifications // ccie training
I was looking all over the net for this information, but was unable to find the exact thing what i was needed, thanks to you i found the right information on time. It saved a lot of time. xtrema cookware
I’m truly enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme? Exceptional work! piezo transducer
Note that it does not copy ALL attributes, so if there is anything you want to keep from the old element to the new one, add it to the function manually. In my case I ensure that onfocus and onblur are retained, for example, and you may also want to keep onclick or other events. My Review Plugin Review | Ferienhäuser in Dänemark
I would like to show my appreciation of your writing skill and ability to make audience, read the whole thing to the end. I'd like to read more of your blogs and to talk about my thoughts with you. I will be your frequent website visitor, that’s for certain.LG WM3987HW
A comprehensively detailed and attention grabbing review that you wrote in this article. I am really convinced the way you look. The way you describe the whole thing is simple and understandable.fauteuils
Informative content like you've written here is usually rather drab and lacking in varying views. You, on the other hand have managed to make this interesting and varied. I share many of your unique thoughts. http://www.samsung1080phdtv.net/
I thought it was going to be some boring old post, but it really compensated for my time. ..biogetica
I was very happy that I discovered this website. I needed to thank you for this excellent information!! I undoubtedly appreciated every bit of it and I have bookmarked your blog to check out the new stuff you post down the road.disability claims lawyer philadelphia pa
Hello This is very nice and informative article,there is too much to learn and this kind of article are rare to find.thanks for sharing such interested article.Rolex watches
Hello Great write-up, I am a big believer in commenting on blogs to assist the weblog writers know that they’ve added one thing worthwhile to the world large net!Anyway, in my language, there aren’t a lot good source like this.
swimming pool enclosures
Hello I must say i enjoyed this kind of post, if I have your permission am able to duplicate this post to my personal website and share it with other people as well. Naturally I am going to give the original credits to you only.
parts washers
I am absolutely amazed at how terrific the stuff is on this site. I have saved this webpage and I truly intend on visiting the site in the upcoming days. Keep up the excellent work!
Gorilla Lug Nuts
Hello I Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this.
home intercom systems
I am glad to have landed in the post for its useful lesson on introduction of the menu attributes module in drupal. I think I've been benefited by the essential tutorial. Thanks
Cleveland brothers power systems
This was really something very special and interesting. Hopefully I can really learn so much from this valuable information. Thanks
kitchen wall sayings
Post new comment