Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to the change a formfield type with javascript? 1

Status
Not open for further replies.

owenbrown

MIS
May 22, 2003
32
US
//when the click off email1 it will change it from a text field to a password field
<script>
function change2pass(form){
form.email.type='password';
}
</script>

<input type=text name=email1 size=9 onblur=change2pass(this.form)>
<input type=text name=email2 size=9>

However it gives me the error, could not get the type property?
Is this possible?
 
interesting...Mozilla Firebird lets you do it, but IE doesn't. we'll use that to our advantage and create an alternate method for IE:

Code:
<script type=&quot;text/javascript&quot;>
function change2pass(oText){
	try {
	  oText.type = &quot;password&quot;;
	}
	catch(E) {			
		var oPwd = document.createElement(&quot;input&quot;);
		oPwd.type = &quot;password&quot;;
		oPwd.value = oText.value;
		oPwd.size = oText.size;
		oPwd.name = oText.name;

		oText.form.insertBefore(oPwd, oText);
		oText.removeNode(true);
	}
}
</script>

<input type=&quot;text&quot; name=&quot;email1&quot; size=&quot;9&quot; onblur=&quot;change2pass(this);&quot; />
<input type=&quot;text&quot; name=&quot;email2&quot; size=&quot;9&quot; />

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
To quote Microsoft:

&quot;As of Microsoft® Internet Explorer 5, the type property is read/write-once, but only when an input element is created with the createElement method and before it is added to the document.&quot;

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top