Dear friends,
Is it possible to change item type in java script. for example change type text to password.
Thanks
Sanoop
Dear friends,
Is it possible to change item type in java script. for example change type text to password.
Thanks
Sanoop
Try the following, just edit out what you need to.
Hope this helps.Code:<html> <head> <script type="text/javascript"> function changeField() { var field = document.testForm.textField; if (field.type == "text") { test = false; field.type = "password"; } else { field.type = "text"; } } </script> </head> <body> <form name="testForm"> <input type="" name="textField"> </form> <a href="#" onclick="changeField(); return false">Change Field </a> </body> </html>
Added Later: There's probably a much better way of doing this, but I'm not sure. The above script has been tested in FF and it works.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design
Thank for your repaly.
there is an error while running this code "could not get the type property" at line no 10(field.type = "password").
document.testForm.textField.type = "text" also tried
Slight Modifications:
Should work. Untested.HTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Change Field</title> <script type="text/javascript"> function changeField() { var field = document.forms['testForm'].elements['textField']; if (field.getAttribute("type") == "text") { field.setAttribute("type","password"); } else { field.setAttribute("type","text"); } } </script> </head> <body> <form name="testForm"> <input type="text" name="textField"> </form> <a href="javascript:changeField()">Change Field </a> </body> </html>
Last edited by tech_support; 01-30-2007 at 04:34 AM.
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
this code also not working in IE. field.setAttribute function is not supporting in IE
Well, time to use another method:
HTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Change Field</title> <script type="text/javascript"> var switcher = 0; function changeField() { var textfield = document.forms['testForm'].elements['textField']; var passfield = document.forms['testForm'].elements['passField']; if (switcher == 0) { textfield.style.display = "none" passfield.value = textfield.value passfield.style.display = "block" switcher++ } else { textfield.style.display = "block" textfield.value = passfield.value passfield.style.display = "none" switcher-- } } </script> </head> <body> <form name="testForm"> <input type="text" name="textField"> <input type="password" name="passField" style="display:none"> </form> <a href="javascript:changeField()">Change Field </a> </body> </html>
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Oh, so this is basically a cross-post.
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
Bookmarks