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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide Textboxes 2

Status
Not open for further replies.

AgentM

MIS
Joined
Jun 6, 2001
Messages
387
Location
US
I am trying to hide a text box and display another, when the user clicks a checkbox.

Any ideas higly appreciated

Rosh
 
Here you go...
Code:
<html>
<script language=&quot;javascript&quot;>
	function SwitchTextBox(){
		
		var z=document.forms.frmDemo
		
		if (z.chk0.checked==true){
			z.txt0.style.visibility = &quot;hidden&quot;
			z.txt1.style.visibility = &quot;visible&quot;
		}
		else{
			z.txt0.style.visibility = &quot;visible&quot;
			z.txt1.style.visibility = &quot;hidden&quot;		
		}
	
	}

</script>
<body onLoad=&quot;SwitchTextBox();&quot;>
	<form id=frmDemo name=frmDemo>
		<input type=checkbox id=chk0 name=chk0 onClick=&quot;SwitchTextBox();&quot; checked><br>
		<input type=text id=txt0 name=txt0><br>
		<input type=text id=txt1 name=txt1>
	</form>
</body>
</html>

Hope it helps, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
That works great.....
Thank you very much

I am new to Javascript
Could you recomend some advanced online turorials.

Also can you tell me Why did u use <body onload=Functioname()>

What if I have two forms or more thatn two functions that need to be executed.

Rosh
 
Could you recomend some advanced online turorials.
---------
---------

Also can you tell me Why did u use <body onload=Functioname()>
---------
So as to set the initial state of hidden/visible of the text boxes. The &quot;checked&quot; property at the end of the input type=checkbox controls this.
---------

What if I have two forms or more thatn two functions that need to be executed.
---------
two forms would require a slightly different, more modular, approach. See below (demonstrates everything you asked about)...
two (or more) functions can be executed by separating the functions with &quot;;&quot; ala onClick=&quot;DoFunction1();DoFunction2();&quot;
---------

Code:
<html>
<script language=&quot;javascript&quot;>
	function SwitchTextBox(oForm){
		
		var z=document.forms[oForm]
		
		if (z.chk0.checked==true){
			z.txt0.style.visibility = &quot;hidden&quot;
			z.txt1.style.visibility = &quot;visible&quot;
		}
		else{
			z.txt0.style.visibility = &quot;visible&quot;
			z.txt1.style.visibility = &quot;hidden&quot;		
		}
	
	}

</script>
<body onLoad=&quot;SwitchTextBox('frmDemo1');SwitchTextBox('frmDemo2');&quot;>
	<p>Form 1:<br>
	<form id=frmDemo1 name=frmDemo1>
		<input type=checkbox id=chk0 name=chk0 onClick=&quot;SwitchTextBox('frmDemo1');&quot; checked><br>
		1: <input type=text id=txt0 name=txt0><br>
		2: <input type=text id=txt1 name=txt1>
	</form></p>
	<p>Form 2:<br>
	<form id=frmDemo2 name=frmDemo2>
		<input type=checkbox id=chk0 name=chk0 onClick=&quot;SwitchTextBox('frmDemo2');&quot;><br>
		1: <input type=text id=txt0 name=txt0><br>
		2: <input type=text id=txt1 name=txt1>
	</form></p>
</body>
</html>
Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Thank you Very Very Very much..

Rosh
 
A javaScript problem
I get an error in the bottom status bar of IE when the onchange event is called , here's the code..
What am I missing?

<HTML>
<BODY>
<SCRIPT language=&quot;JavaScript&quot;>
function CalSelDetails()
{
var Sid = document.myform.txtSid.value;
document.myform.txtSname.value = Sid;
}
end function
</SCRIPT>

<FORM name=&quot;myform&quot;>
Id: <INPUT size=&quot;20&quot; type=&quot;text&quot; id= &quot;txtSid&quot; name=&quot;txtSid&quot; onchange=&quot;CalSelDetails();&quot;> <BR>
name:
<INPUT size=&quot;20&quot; type=&quot;text&quot; id=&quot;txtSname&quot; name=&quot;txtSname&quot; ><BR>
Department:
<INPUT size=&quot;20&quot; type=&quot;text&quot; name=&quot;txtSdept&quot;>

</FORM>
</BODY>
</HTML>

 
I think that if you take out &quot;end function&quot; it should work. I think that &quot;end function&quot; was meant to be a comment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top