...

View Full Version : Hide/Show HTML with a radio button



John76
10-15-2003, 04:10 PM
Hi,

I have a form where the User needs to select whether or not they are a US Citizen or not.

If they select "NO", they need to fill in a text box of their citizenship (which would be required).

I only want the "NO" text box to show if the User selects the radio button "No".

Here is the HTML code:

<TABLE>
<FORM>
<TR>
<TD><FONT FACE="Arial" SIZE="-1">United States Citizen:</FONT></TD>
<TD><FONT FACE="Arial" SIZE="-1">
<INPUT TYPE="radio" NAME="UnitedStatesCitizen" VALUE="Yes"> Yes
<INPUT TYPE="radio" NAME="UnitedStatesCitizen" VALUE="No"> No<BR>
If No, What Country
<INPUT TYPE="text" NAME="CountryCitizen" VALUE="" SIZE="13" MAXLENGTH="25">
</FONT>
</TD>
</TR>
</FORM>
</TABLE>

Thanks in advance.

John

Mr J
10-15-2003, 09:52 PM
Please try the following



<TABLE>
<FORM name="f1">
<TR>
<TD><FONT FACE="Arial" SIZE="-1">United States Citizen:</FONT></TD>
<TD><FONT FACE="Arial" SIZE="-1">
<INPUT TYPE="radio" NAME="UnitedStatesCitizen" VALUE="Yes" checked onclick="document.f1.CountryCitizen.style.visibility='visible'"> Yes
<INPUT TYPE="radio" NAME="UnitedStatesCitizen" VALUE="No" onclick="document.f1.CountryCitizen.style.visibility='hidden'"> No<BR>
If No, What Country
<INPUT TYPE="text" NAME="CountryCitizen" VALUE="" SIZE="13" MAXLENGTH="25">
</FONT>
</TD>
</TR>
</FORM>
</TABLE>

Willy Duitt
10-16-2003, 01:15 AM
John;

Mr. J provided you with the difinitve solution and although you
only requested that the text box be hidden. It seemed odd to me
to have If No, What Country appearing without an input.


<BODY onLoad="document.all.CitizenNo.style.visibility='hidden'">

<TABLE>
<FORM name="f1">
<TR>
<TD><FONT FACE="Arial" SIZE="-1">United States Citizen:
<INPUT TYPE="radio" NAME="UnitedStatesCitizen" VALUE="Yes" checked onclick="document.all.CitizenNo.style.visibility='hidden'"> Yes
<INPUT TYPE="radio" NAME="UnitedStatesCitizen" VALUE="No" onclick="document.all.CitizenNo.style.visibility='visible'"> No
<BR>
<SPAN ID="CitizenNo">
If No, What Country
<INPUT TYPE="text" NAME="CountryCitizen" VALUE="" SIZE="13" MAXLENGTH="25">
</SPAN>
</FONT>
</TD>
</TR>
</FORM>
</TABLE>

.....Willy

John76
10-16-2003, 03:18 PM
Willy,

You were right about "If No, What Country" showing, so thanks for the code. It's exactly what I was looking for.

Mr J - Thanks for the code also.

John

Mr J
10-16-2003, 04:33 PM
But please use

document.getElementById("CitizenNo")

because document.all is IE4

:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum