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

Dynamic Forms - Change Content depending on checkbox?

Status
Not open for further replies.

TonyCronin

Programmer
Jul 16, 2001
47
GB
I am looking to try and create a form in html that will chnage depending on whether user ...

I have a one checkbox that I would like to use to determine whether or not a text field is displayed.. here is what I have done so far. I have used OnClick but checkbox doesn't refresh... please help

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<p align=&quot;center&quot;>
<script>
var param1
</script>
</p>
<form name=&quot;PageOne&quot; method=&quot;post&quot; action=&quot;&quot;>
<table width=&quot;500&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; align=&quot;center&quot;>
<tr>
<td width=&quot;225&quot; height=&quot;35&quot;>Please enter your Login</td>
<td width=&quot;275&quot; height=&quot;35&quot;>
<input type=&quot;text&quot; name=&quot;Login&quot;>
</td>
</tr>
<tr>
<td width=&quot;225&quot; height=&quot;35&quot;>Do you have an UserID</td>
<td width=&quot;275&quot; valign=&quot;middle&quot; height=&quot;35&quot;>
<input type=&quot;checkbox&quot; onClick=&quot;param1=1&quot; name=&quot;HaveID&quot;>
</td>
</tr>
<% If param1 = 1 Then %>
<tr>
<td width=&quot;225&quot; height=&quot;35&quot;>Please enter your UserID</td>
<td width=&quot;275&quot; height=&quot;35&quot;>
<input type=&quot;text&quot; name=&quot;UserID&quot;>
</td>
</tr>
<% Else %>
<tr>
<td colspan=&quot;2&quot;>*If you do not have a User ID, please contact your local
<a href=&quot;mailto:%20&quot;>NT administrator</a> in order to create one. </td>
</tr>
<% End If %>
<tr>
<td width=&quot;225&quot; height=&quot;35&quot;>
<div align=&quot;right&quot;>
<input type=&quot;reset&quot; name=&quot;Submit2&quot; value=&quot;Clear&quot;>
</div>
</td>
<td width=&quot;275&quot; height=&quot;35&quot;>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Next&quot;>
</td>
</tr>
</table>
</form>

</body>
</html>

 
I've done this before, but using layers. Dreamweaver has a
nice little show/hide layer tool that can add code to your
page, but I'll paste it here in case you're not using
Dreameaver:

Code:
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

Then, you can add this function to the onclick or on
check or whatever function of the checkbox:

Code:
function click_info() {
	if (isNS6()) {
		elm = document.getElementById(&quot;Layer1&quot;);
		elm.style.visibility = &quot;visible&quot;;
		elm = document.getElementById(&quot;Layer2&quot;);
		elm.style.visibility = &quot;hidden&quot;;
	}
	else {
	MM_showHideLayers('Layer1','','hide','Layer2','','show');
	}
}

As you can see, it does a browser check (which is more
code), but thats another thing. The code above should work
for both NS and IE browsers.

You would also have to add one for each the check and
uncheck, and make sure the hide/show stuff is in the right
place. (I edited this heavily to make it less verbose than
necessary.)

Hope that helps,
MG
 
Excellent... I have managed to crack it..Thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top