473,228 Members | 1,662 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

Changing an INPUT textbox's TYPE property on the fly

Hi All

Could somebody confirm if and how I can change the TYPE of a textbox from
PASSWORD to TEXT depending on whether a user checks a checkbox.

In essence I have a login and password form and the end user wants the
option to check a checkbox to make the Password textbox show normal text
rather than the asterisks. If the checkbox is unchecked then it shows the
asterisks when entering the password.

Possible?

Rgds

Robbie


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #1
3 11515
Ivo
"Astra" wrote
Could somebody confirm if and how I can change the TYPE of a textbox from
PASSWORD to TEXT depending on whether a user checks a checkbox.


You cannot directly change the input element's type. I got an error when I
tried it in IE. You can however show and hide two different elements of
course:

<script type="text/javascript">
function showpass(el){
el.form.text.style.display=el.checked?'':'none';
el.form.pass.style.display=el.checked?'none':'';
}
function syncpass(el){
el.form[el.name==='text'?'pass':'text'].value=el.value;
}
</script>

<form ... >
<label>Pass:</label>
<input type="text" name="text" value="test" onkeyup="syncpass(this);"
style="display:none">
<input type="password" name="pass" value="test" onkeyup="syncpass(this);">
<label>Show:</label>
<input type="checkbox" onclick="showpass(this);">
</form>
--
Ivo
Jul 23 '05 #2
*Astra* wrote in comp.lang.javascript:
Could somebody confirm if and how I can change the TYPE of a textbox from
PASSWORD to TEXT depending on whether a user checks a checkbox.


Please don't multi-post - 2 replies in news:alt.www.webmaster
--
Andrew Urquhart
- FAQ: http://www.jibbering.com/faq/
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Contact me: http://andrewu.co.uk/contact/
Jul 23 '05 #3
Many thanks Ivo

Rgds Robbie

"Ivo" <no@thank.you> wrote in message
news:41***********************@news.wanadoo.nl...
"Astra" wrote
Could somebody confirm if and how I can change the TYPE of a textbox from
PASSWORD to TEXT depending on whether a user checks a checkbox.


You cannot directly change the input element's type. I got an error when I
tried it in IE. You can however show and hide two different elements of
course:

<script type="text/javascript">
function showpass(el){
el.form.text.style.display=el.checked?'':'none';
el.form.pass.style.display=el.checked?'none':'';
}
function syncpass(el){
el.form[el.name==='text'?'pass':'text'].value=el.value;
}
</script>

<form ... >
<label>Pass:</label>
<input type="text" name="text" value="test" onkeyup="syncpass(this);"
style="display:none">
<input type="password" name="pass" value="test" onkeyup="syncpass(this);">
<label>Show:</label>
<input type="checkbox" onclick="showpass(this);">
</form>
--
Ivo

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor...
7
by: Ed West | last post by:
Hello, I have a simple form with some input boxes. After validation if one fails, then I would like to at the top of the page say something like "The following fields in red are required" and...
6
by: A Traveler | last post by:
I know in a css file, i can declare a style which will apply to a given HTML tag, specifically, i am looking at an INPUT tag. Is there any way in which i can create a style section which will apply...
3
by: David Virgil Hobbs | last post by:
I discovered how to write out the inner HTML of the contents of an Iframe; I want to know how to write out the outerHTML of the contents of an Iframe. frames.document.body.innerHTML allows me to...
2
by: yawnmoth | last post by:
Say I have two input elements and that I wanted to make it so that when the first ones input was what it should be, the focus would automatically be shifted to the next input element. ie....
1
by: jjwhite01 | last post by:
I am working on a web form that contains a Calendar control with an image button that makes the calendar appear and disappear. However, I would like to set the visible property of the Calendar...
6
by: Brandon McCombs | last post by:
Hello, I have a Form that contains some configuration information. One of the settings is for SSL. There is a checkbox that I want to check to make 2 textboxes un-editable so that a user can...
4
by: John Kotuby | last post by:
Hi all, I have a simple user-form which accepts contact and profile information for the user to edit and save. All the textboxes are working fine and displaying the expected data, both when the...
8
by: mike_solomon | last post by:
I have a button <input type="submit" name="Delete" value="Delete"> This code can not be changed I want to use Javascript to change the type I tried:
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.