Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hide/Show HTML with a radio button

    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

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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>


  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Aug 2003
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks!

    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

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    But please use

    document.getElementById("CitizenNo")

    because document.all is IE4



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •