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

Visible & hidden

Status
Not open for further replies.

Draug

Programmer
Apr 18, 2001
77
CA
Greetings,

I have two check boxes; only 1 of which can be selected at one time. There is a corresponding text box that is to be displayed. Checkbox 1means that textbox1 is to be displayed. Checkbox 2means that textbox2 is to be displayed.

It is easy enough to hide one, and make the other visible. BUT, I want them to be in the same location.

Can anyone tell me how to do it? At this point, I am only concerned with IE 5.x.

Thank you so much.
 
Before I answer this, can I ask why you want two textboxes to show up in the same location depending on what checkbox is selected?
Or... Why not just have one static textbox in the location you want to accept any data entered and then use javascript to check what checkbox is checked so you know what the text in the textbox is relevant to? Klae

You're only as good as your last answer!
 
Well,
I'm going to bed at 00:52am in the UK, So I'll post the code anyway...

Code:
<HTML>
<HEAD>
<TITLE>test</TITLE>
<STYLE type=&quot;text/css&quot;>
.textboxclass
{
	position: absolute;
	visibility: hidden;
	z-index: 0;
	left: 20px;
	top: 300px;
}
</STYLE>
<SCRIPT language=&quot;JavaScript&quot;>
var prevTbox = &quot;&quot;;
var prevChkBox = &quot;&quot;;

function showTB(tbox, chkbox)
{
	if (prevChkBox != &quot;&quot;)
	{
		eval(&quot;window.&quot; + prevChkBox + &quot;.checked = false&quot;);
	}
	eval(&quot;window.&quot; + chkbox + &quot;.checked = true&quot;);
	if (prevTbox != &quot;&quot;)
	{
		eval(&quot;window.&quot; + prevTbox + &quot;.style.zIndex = 0&quot;);
		eval(&quot;window.&quot; + prevTbox + &quot;.style.visibility = 'hidden'&quot;);
	}
	eval(&quot;window.&quot; + tbox + &quot;.style.zIndex = 1&quot;);
	eval(&quot;window.&quot; + tbox + &quot;.style.visibility = 'visible'&quot;);
	prevTbox = tbox;
	prevChkBox = chkbox;
}
</SCRIPT>
</HEAD>
<BODY >
<INPUT type=radio onClick=&quot;showTB('textbox1', 'chk1');&quot; id=chk1>
<INPUT type=radio onClick=&quot;showTB('textbox2', 'chk2');&quot; id=chk2>
<INPUT type=text class=&quot;textboxclass&quot; id=&quot;textbox1&quot; value=&quot;textbox1&quot;>
<INPUT type=text class=&quot;textboxclass&quot; id=&quot;textbox2&quot; value=&quot;textbox2&quot;>
</BODY>
</HTML>
Klae

You're only as good as your last answer!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top