473,385 Members | 1,312 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,385 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 11526
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:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.