By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

Changing an INPUT textbox's TYPE property on the fly

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
*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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.