Display/Hide Fields using radio buttons

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DettCom

    #1

    Display/Hide Fields using radio buttons

    Hello,

    I would like to be able to display or hide fields based on whether a
    specific Yes/No radio button is selected. This is in conjunction with
    a posting a just made here in the same group related to checkboxes.

    Thanks!!!
  • Stuart Palmer

    #2
    Re: Display/Hide Fields using radio buttons

    You can do this with divs and showing and hiding the divs as required based
    on the radios selected.
    I do this all the time with stuff I do for work.

    Stu

    "DettCom" <scott@dettcom. com> wrote in message
    news:ca0599d2.0 409290501.488df 5ab@posting.goo gle.com...[color=blue]
    > Hello,
    >
    > I would like to be able to display or hide fields based on whether a
    > specific Yes/No radio button is selected. This is in conjunction with
    > a posting a just made here in the same group related to checkboxes.
    >
    > Thanks!!![/color]


    Comment

    • Robert

      #3
      Re: Display/Hide Fields using radio buttons

      In article <ca0599d2.04092 90501.488df5ab@ posting.google. com>,
      scott@dettcom.c om (DettCom) wrote:
      [color=blue]
      > I would like to be able to display or hide fields based on whether a
      > specific Yes/No radio button is selected. This is in conjunction with
      > a posting a just made here in the same group related to checkboxes.[/color]


      This javascript should help. The validation is very simple and there
      are a lot of alerts so you can follow what is happening.

      Robert

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <title>Radio buttons</title>

      <style type="text/css">
      ..formStyle {position:relat ive;}
      </style>

      <script type="text/javascript">

      function validate()
      {

      var x = document.forms["myForm"];
      var checkedButton;

      // Figure out which radio button was pressed
      checkedButton = findValue(x.rec eiveVia);

      var varName = x.theName.value ;
      var varEmail = x.theEmail.valu e;
      var varAddress = x.theAddress.va lue;

      alert("checkedB utton = " + checkedButton +
      " varName = " + varName +
      " varEmail = " + varEmail +
      " varAddress = " + varAddress);

      // I changed submitOK to a boolean variable.
      var submitOK = true;

      // Validate email: name and email

      if (checkedButton == "byEmail")
      {
      alert("verifyin g email fields.");

      if (varName == '')
      {
      alert("Please fill in your Name");
      submitOK = false;
      }
      if (varEmail == '')
      {
      alert("Please fill in Email");
      submitOK = false;
      }
      if (varAddress != '')
      {
      alert("Please erase the address field.");
      submitOK = false;
      }

      return submitOK;

      }

      // Validate print: name, email, and address

      else if (checkedButton= ="printed")
      {
      alert("Verifyin g printed fields");
      // Error message should be in the order on the form
      if (varName.length == '')
      {
      alert("Please fill in your Name");
      submitOK = false;
      }
      if (varEmail == '')
      {
      alert("Please fill in Email");
      submitOK = false;
      }
      if (varAddress == '')
      {
      alert("You must enter your Address");
      submitOK = false;
      }

      return submitOK;
      }
      else
      {
      alert("You need to select either email or print.");
      return false;
      }

      }

      function showHidden(doWh at)
      {
      // Check if the getElementById method is available
      if (document.getEl ementById)
      {
      document.getEle mentById("field 3").style.displ ay = doWhat;
      }
      else if (document.all)
      {
      alert("Running an older version of IE.");
      document.all.fi eld3.style.disp lay = doWhat;
      }
      else
      { alert("Cannot change visibility of address field"); }
      }

      // See which radio button is selected and return its value
      function findValue(obj)
      {
      var i, theValue;
      theValue = null;

      for (i=0;i<obj.leng th;i++)
      {
      if (obj[i].checked == true)
      {
      theValue = obj[i].value;
      break;
      }
      }

      return theValue;
      }
      </script>

      </head>

      <body>

      <p>Please try out our form.</p>

      <form name="myForm"
      action="http://www.nonamedomai n.com"
      method="POST"
      onsubmit="alert ('submitting'); return validate();">
      <p><input type="radio" name="receiveVi a" value="printed"
      onclick="showHi dden('');">&nbs p;Printed
      brochure</p>
      <p><input type="radio" name="receiveVi a" value="byEmail"
      onclick="showHi dden('none');
      document.forms['myForm'].theAddress.val ue = '';">&nbsp;Via
      Email</p>
      <p>Name:<br>
      <input type="text" name="theName" size="20"><br>< br>
      Email:<br>
      <input type="text" name="theEmail" size="20"><br>
      <script type="text/javascript">
      // Only insert a div if we can change it
      if (document.getEl ementById || document.all)
      { document.write( "<div id='field3' class='formStyl e'>");}
      </script>
      Postal address:<br>
      <input type="text" name="theAddres s" size="40">
      <script type="text/javascript">
      if (document.getEl ementById || document.all)
      { document.write( "</div>");}
      </script>
      </p>

      <p><input type="submit"
      border="0"
      value="Submit form"
      width="75"
      height="17"
      ALT="Submit button"></p>

      </form>

      <script type="text/javascript">
      // In the case of a reload, the radio button may already be clicked.
      // This code needs to be after the form.
      var x = document.forms["myForm"];
      if (x.receiveVia[0].checked == true)
      { showHidden(''); }
      else if (x.receiveVia[1].checked == true)
      { showHidden('non e');}
      else
      { ;}

      </script>
      </body>
      </html>

      Comment

      • DettCom

        #4
        Re: Display/Hide Fields using radio buttons

        Stuart, thanks for the reply. However, that is what I have been trying
        with checkboxes (assume it is the same in theory). Here is the simple
        code that i have been experiencing with:

        <input type="checkbox"
        onclick="if(doc ument.all)del.s tyle.display='n one'"">
        <div id ="del">
        Your address <input type="text" name="address">
        .....the rest of the deleivery fields
        </div>



        For the life of me.... I cannot figure it out.


        "Stuart Palmer" <tryandspamme@y oucant.com> wrote in message news:<2s00dgF1e p0f6U1@uni-berlin.de>...[color=blue]
        > You can do this with divs and showing and hiding the divs as required based
        > on the radios selected.
        > I do this all the time with stuff I do for work.
        >
        > Stu
        >
        > "DettCom" <scott@dettcom. com> wrote in message
        > news:ca0599d2.0 409290501.488df 5ab@posting.goo gle.com...[color=green]
        > > Hello,
        > >
        > > I would like to be able to display or hide fields based on whether a
        > > specific Yes/No radio button is selected. This is in conjunction with
        > > a posting a just made here in the same group related to checkboxes.
        > >
        > > Thanks!!![/color][/color]

        Comment

        • Evertjan.

          #5
          Re: Display/Hide Fields using radio buttons

          DettCom wrote on 29 sep 2004 in comp.lang.javas cript:
          [color=blue]
          > Stuart, thanks for the reply. However, that is what I have been trying
          > with checkboxes (assume it is the same in theory). Here is the simple
          > code that i have been experiencing with:
          >
          > <input type="checkbox"
          > onclick="if(doc ument.all)del.s tyle.display='n one'"">
          > <div id ="del">
          > Your address <input type="text" name="address">
          > ....the rest of the deleivery fields
          > </div>[/color]

          <input type="checkbox" checked
          onclick="getEle mentById('del') .style.display=
          (this.checked)? '':'none'">


          <div id ="del">
          Your address <input type="text" name="address">
          .....the rest of the deleivery fields
          </div>

          IE6 tested, cross browser suspected.

          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress,
          but let us keep the discussions in the newsgroup)

          Comment

          • RobG

            #6
            Re: Display/Hide Fields using radio buttons

            Evertjan. wrote:

            [snip][color=blue]
            > <input type="checkbox" checked
            > onclick="getEle mentById('del') .style.display=
            > (this.checked)? '':'none'">
            >
            >
            > <div id ="del">
            > Your address <input type="text" name="address">
            > .....the rest of the deleivery fields
            > </div>[/color]
            [snip]

            You should also play with the element's visibility attribute
            to see if that suits your purpose too. If you set
            display='none', the element takes up zero space on the page
            and all the other elements whose position on the page is
            based on the one you just hid will move (maybe quite a lot).
            Similarly in reverse when you display it, both of which
            can be quite disconcerting for users.

            Using the visibility attribute, the element still takes up
            room on the page so when you hide/reveal it, nothing moves
            (well, sometimes things move a little bit in some browsers...).

            Lastly, make sure your page still works with JavaScript
            turned off - sometimes things are hidden using an in-line
            stylen or CSS then revealed using JS to modify the style.
            Users with JS turned of can't get to see the hidden do-dad.

            Cheers, Rob.

            Comment

            • Evertjan.

              #7
              Re: Display/Hide Fields using radio buttons

              RobG wrote on 30 sep 2004 in comp.lang.javas cript:[color=blue]
              > Lastly, make sure your page still works with JavaScript
              > turned off - sometimes things are hidden using an in-line
              > stylen or CSS then revealed using JS to modify the style.
              > Users with JS turned of can't get to see the hidden do-dad.[/color]

              I don't agree completely.

              If users want to have their JS turned off,
              one should have them recognize what they miss,
              not accommodate them with a subquality page,
              unless you really need them as customers.


              <noscript>
              You silly ass!<br>
              Without javascript this page is not what it should be<br>
              Better look elswhere or change your ways
              </noscript>

              or

              <div id='scripted'>
              You silly ass!<br>
              Without javascript this page is not what it should be<br>
              Better look elswhere or change your ways
              </div>
              <script>
              document.getEle mentById('scrip ted').style.dis play='none'
              </script>


              --
              Evertjan.
              The Netherlands.
              (Please change the x'es to dots in my emailaddress,
              but let us keep the discussions in the newsgroup)

              Comment

              • DettCom

                #8
                Re: Display/Hide Fields using radio buttons

                Robert, that works!!! I have another posting that basically needs to
                do the same thing, but will use a single checkbox. Can you help???

                Thanks!!!





                Robert <rccharles@my-deja.com> wrote in message news:<rccharles-79359C.13325329 092004@news1.we st.earthlink.ne t>...[color=blue]
                > In article <ca0599d2.04092 90501.488df5ab@ posting.google. com>,
                > scott@dettcom.c om (DettCom) wrote:
                >[color=green]
                > > I would like to be able to display or hide fields based on whether a
                > > specific Yes/No radio button is selected. This is in conjunction with
                > > a posting a just made here in the same group related to checkboxes.[/color]
                >
                >
                > This javascript should help. The validation is very simple and there
                > are a lot of alerts so you can follow what is happening.
                >
                > Robert
                >
                > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                > "http://www.w3.org/TR/html4/loose.dtd">
                > <html>
                > <head>
                > <title>Radio buttons</title>
                >
                > <style type="text/css">
                > .formStyle {position:relat ive;}
                > </style>
                >
                > <script type="text/javascript">
                >
                > function validate()
                > {
                >
                > var x = document.forms["myForm"];
                > var checkedButton;
                >
                > // Figure out which radio button was pressed
                > checkedButton = findValue(x.rec eiveVia);
                >
                > var varName = x.theName.value ;
                > var varEmail = x.theEmail.valu e;
                > var varAddress = x.theAddress.va lue;
                >
                > alert("checkedB utton = " + checkedButton +
                > " varName = " + varName +
                > " varEmail = " + varEmail +
                > " varAddress = " + varAddress);
                >
                > // I changed submitOK to a boolean variable.
                > var submitOK = true;
                >
                > // Validate email: name and email
                >
                > if (checkedButton == "byEmail")
                > {
                > alert("verifyin g email fields.");
                >
                > if (varName == '')
                > {
                > alert("Please fill in your Name");
                > submitOK = false;
                > }
                > if (varEmail == '')
                > {
                > alert("Please fill in Email");
                > submitOK = false;
                > }
                > if (varAddress != '')
                > {
                > alert("Please erase the address field.");
                > submitOK = false;
                > }
                >
                > return submitOK;
                >
                > }
                >
                > // Validate print: name, email, and address
                >
                > else if (checkedButton= ="printed")
                > {
                > alert("Verifyin g printed fields");
                > // Error message should be in the order on the form
                > if (varName.length == '')
                > {
                > alert("Please fill in your Name");
                > submitOK = false;
                > }
                > if (varEmail == '')
                > {
                > alert("Please fill in Email");
                > submitOK = false;
                > }
                > if (varAddress == '')
                > {
                > alert("You must enter your Address");
                > submitOK = false;
                > }
                >
                > return submitOK;
                > }
                > else
                > {
                > alert("You need to select either email or print.");
                > return false;
                > }
                >
                > }
                >
                > function showHidden(doWh at)
                > {
                > // Check if the getElementById method is available
                > if (document.getEl ementById)
                > {
                > document.getEle mentById("field 3").style.displ ay = doWhat;
                > }
                > else if (document.all)
                > {
                > alert("Running an older version of IE.");
                > document.all.fi eld3.style.disp lay = doWhat;
                > }
                > else
                > { alert("Cannot change visibility of address field"); }
                > }
                >
                > // See which radio button is selected and return its value
                > function findValue(obj)
                > {
                > var i, theValue;
                > theValue = null;
                >
                > for (i=0;i<obj.leng th;i++)
                > {
                > if (obj[i].checked == true)
                > {
                > theValue = obj[i].value;
                > break;
                > }
                > }
                >
                > return theValue;
                > }
                > </script>
                >
                > </head>
                >
                > <body>
                >
                > <p>Please try out our form.</p>
                >
                > <form name="myForm"
                > action="http://www.nonamedomai n.com"
                > method="POST"
                > onsubmit="alert ('submitting'); return validate();">
                > <p><input type="radio" name="receiveVi a" value="printed"
                > onclick="showHi dden('');">&nbs p;Printed
                > brochure</p>
                > <p><input type="radio" name="receiveVi a" value="byEmail"
                > onclick="showHi dden('none');
                > document.forms['myForm'].theAddress.val ue = '';">&nbsp;Via
                > Email</p>
                > <p>Name:<br>
                > <input type="text" name="theName" size="20"><br>< br>
                > Email:<br>
                > <input type="text" name="theEmail" size="20"><br>
                > <script type="text/javascript">
                > // Only insert a div if we can change it
                > if (document.getEl ementById || document.all)
                > { document.write( "<div id='field3' class='formStyl e'>");}
                > </script>
                > Postal address:<br>
                > <input type="text" name="theAddres s" size="40">
                > <script type="text/javascript">
                > if (document.getEl ementById || document.all)
                > { document.write( "</div>");}
                > </script>
                > </p>
                >
                > <p><input type="submit"
                > border="0"
                > value="Submit form"
                > width="75"
                > height="17"
                > ALT="Submit button"></p>
                >
                > </form>
                >
                > <script type="text/javascript">
                > // In the case of a reload, the radio button may already be clicked.
                > // This code needs to be after the form.
                > var x = document.forms["myForm"];
                > if (x.receiveVia[0].checked == true)
                > { showHidden(''); }
                > else if (x.receiveVia[1].checked == true)
                > { showHidden('non e');}
                > else
                > { ;}
                >
                > </script>
                > </body>
                > </html>[/color]

                Comment

                • Michael Winter

                  #9
                  Re: Display/Hide Fields using radio buttons

                  On 30 Sep 2004 07:41:49 GMT, Evertjan. <exjxw.hannivoo rt@interxnl.net >
                  wrote:
                  [color=blue]
                  > RobG wrote on 30 sep 2004 in comp.lang.javas cript:
                  >[color=green]
                  >> Lastly, make sure your page still works with JavaScript
                  >> turned off - sometimes things are hidden using an in-line
                  >> stylen or CSS then revealed using JS to modify the style.
                  >> Users with JS turned of can't get to see the hidden do-dad.[/color]
                  >
                  > I don't agree completely.
                  >
                  > If users want to have their JS turned off,
                  > one should have them recognize what they miss,
                  > not accommodate them with a subquality page,
                  > unless you really need them as customers.[/color]

                  And if they have no control over the settings? What good does that do?

                  A page is hardly substandard if it just shows a few more elements than one
                  that is scripted. It is functional, and that is what matters!

                  [snip]

                  Mike

                  --
                  Michael Winter
                  Replace ".invalid" with ".uk" to reply by e-mail.

                  Comment

                  • Robert

                    #10
                    Re: Display/Hide Fields using radio buttons

                    scott@dettcom.c om (DettCom) wrote in message news:<ca0599d2. 0409300605.7057 b305@posting.go ogle.com>...[color=blue]
                    > Robert, that works!!! I have another posting that basically needs to
                    > do the same thing, but will use a single checkbox. Can you help???[/color]

                    OK, the coding is vary similiar.

                    The code fragment accesses a true/false variable:
                    document.forms["myForm"].elements["receiveVia "].checked

                    Robert

                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                    "http://www.w3.org/TR/html4/loose.dtd">
                    <html>
                    <head>
                    <title>Radio buttons</title>

                    <style type="text/css">
                    ..formStyle {position:relat ive;}
                    </style>

                    <script type="text/javascript">

                    function validate()
                    {

                    var x = document.forms["myForm"];


                    var varName = x.theName.value ;
                    var varEmail = x.theEmail.valu e;
                    var varAddress = x.theAddress.va lue;

                    alert(
                    " varName = " + varName +
                    " varEmail = " + varEmail +
                    " varAddress = " + varAddress);

                    // I changed submitOK to a boolean variable.
                    var submitOK = true;

                    // Validate email: name and email

                    if(x.elements["receiveVia "].checked)
                    {
                    alert("verifyin g email fields.");

                    if (varName == '')
                    {
                    alert("Please fill in your Name");
                    submitOK = false;
                    }
                    if (varEmail == '')
                    {
                    alert("Please fill in Email");
                    submitOK = false;
                    }
                    if (varAddress != '')
                    {
                    alert("Please erase the address field.");
                    submitOK = false;
                    }

                    return submitOK;

                    }

                    // Validate print: name, email, and address

                    else
                    {
                    alert("Verifyin g printed fields");
                    // Error message should be in the order on the form
                    if (varName.length == '')
                    {
                    alert("Please fill in your Name");
                    submitOK = false;
                    }
                    if (varEmail == '')
                    {
                    alert("Please fill in Email");
                    submitOK = false;
                    }
                    if (varAddress == '')
                    {
                    alert("You must enter your Address");
                    submitOK = false;
                    }

                    return submitOK;
                    }

                    }

                    function showHidden(doWh at)
                    {
                    // Check if the getElementById method is available
                    if (document.getEl ementById)
                    {
                    document.getEle mentById("field 3").style.displ ay = doWhat;
                    }
                    else if (document.all)
                    {
                    alert("Running an older version of IE.");
                    document.all.fi eld3.style.disp lay = doWhat;
                    }
                    else
                    { alert("Cannot change visibility of address field"); }
                    }

                    function decideDisplay()
                    {
                    var x = document.forms["myForm"];
                    if (x.receiveVia.c hecked == true)
                    { showHidden('non e');
                    document.forms['myForm'].theAddress.val ue = '';
                    }
                    else
                    { showHidden(''); }
                    }

                    </script>

                    </head>

                    <body>

                    <p>Please try out our form.</p>

                    <form name="myForm"
                    action="http://www.nonamedomai n.com"
                    method="POST"
                    onsubmit="alert ('submitting'); return validate();">
                    <p><input type="checkbox"
                    name="receiveVi a"
                    value=""
                    onclick="decide Display();">&nb sp;Via
                    email</p>
                    <p>Name:<br>
                    <input type="text" name="theName" size="20"><br>< br>
                    Email:<br>
                    <input type="text" name="theEmail" size="20"><br>
                    <script type="text/javascript">
                    // Only insert a div if we can change it
                    if (document.getEl ementById || document.all)
                    { document.write( "<div id='field3' class='formStyl e'>");}
                    </script>
                    Postal address:<br>
                    <input type="text" name="theAddres s" size="40">
                    <script type="text/javascript">
                    if (document.getEl ementById || document.all)
                    { document.write( "</div>");}
                    </script>
                    </p>

                    <p><input type="submit"
                    border="0"
                    value="Submit form"
                    width="75"
                    height="17"
                    ALT="Submit button"></p>

                    </form>

                    <script type="text/javascript">
                    // In the case of a reload, the radio button may already be clicked.
                    // This code needs to be after the form.
                    decideDisplay() ;
                    </script>
                    </body>
                    </html>

                    Comment

                    • Robert

                      #11
                      Re: Display/Hide Fields using radio buttons

                      RobG <rgqld@iinet.ne t.auau> wrote in message news:<YxK6d.150 4$aA.53588@news .optus.net.au>. ..
                      [color=blue]
                      > You should also play with the element's visibility attribute
                      > to see if that suits your purpose too.[/color]


                      In this example, I use both the display and visibility attributes.

                      Robert

                      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                      "http://www.w3.org/TR/html4/loose.dtd">
                      <html>
                      <head>
                      <META http-equiv="content-type" content="text/html; charset=iso-8859-1">
                      <title>CSS Display and Visibility</title>

                      <script type="text/javascript">

                      function validate(x)
                      {
                      var checkedButton;

                      // Figure out which radio button was pressed

                      checkedButton = findValue(x.rec eiveVia);

                      var varName = x.theName.value ;
                      var varEmail = x.theEmail.valu e;
                      var varAddress = x.theAddress.va lue;

                      // I changed submitOK to a boolean variable.
                      var submitOK = true;

                      // Validate email: name and email

                      if (checkedButton == "byEmail")
                      {

                      if (varName == '')
                      {
                      alert("Please fill in your Name");
                      submitOK = false;
                      }
                      if (varEmail == '')
                      {
                      alert("Please fill in Email");
                      submitOK = false;
                      }
                      if (varAddress != '')
                      {
                      alert("Please erase the address field.");
                      submitOK = false;
                      }

                      return submitOK;

                      }

                      // Validate print: name, email, and address

                      else if (checkedButton= ="printed")
                      {
                      // Error messages should be in the order on the form
                      if (varName.length == '')
                      {
                      alert("Please fill in your Name");
                      submitOK = false;
                      }
                      if (varEmail == '')
                      {
                      alert("Please fill in Email");
                      submitOK = false;
                      }
                      if (varAddress == '')
                      {
                      alert("You must enter your Address");
                      submitOK = false;
                      }

                      return submitOK;
                      }
                      else
                      {
                      alert("You need to select either email or print.");
                      return false;
                      }

                      }

                      function vanishHidden(do What)
                      {
                      // Check if the getElementById method is available
                      if (document.getEl ementById)
                      {
                      document.getEle mentById("hideS pan").style.dis play = doWhat;
                      }
                      else if (document.all)
                      {
                      alert("Running an older version of IE.");
                      document.all.hi deSpan.style.di splay = doWhat;
                      }
                      else
                      { alert("Cannot change visibility of address field"); }
                      }


                      function hideHidden(doWh at)
                      {
                      // Check if the getElementById method is available
                      if (document.getEl ementById)
                      {
                      document.getEle mentById("vanis hSpan").style.v isibility = doWhat;
                      }
                      else if (document.all)
                      {
                      alert("Running an older version of IE.");
                      document.all.va nishSpan.style. visibility = doWhat;
                      }
                      else
                      { alert("Cannot change display value of address field"); }
                      }

                      // See which radio button is selected and return its value
                      function findValue(obj)
                      {
                      var i, theValue;
                      theValue = null;

                      for (i=0;i<obj.leng th;i++)
                      {
                      if (obj[i].checked == true)
                      {
                      theValue = obj[i].value;
                      break;
                      }
                      }

                      return theValue;
                      }
                      </script>

                      </head>

                      <body>

                      <p>Please try out our form.</P>
                      <P>This form uses the CSS display
                      and visibility style attributes. When you click on the
                      radio button email, Javascript code uses the display attribute
                      property of hidden to exclude the address field from the display.
                      No space will be taken up in the window.
                      When you click on the no radio button, Javascript code uses the
                      visibility attribute property of none to make the literature
                      catagories invisible. Space will be taken up in the window.</p>

                      <form name="myForm"
                      action="http://www.notavalidur l.com"
                      method="GET"
                      onsubmit="retur n validate(docume nt.forms['myForm']);">
                      <p>
                      <input type="radio"
                      name="receiveVi a"
                      value="printed"
                      onclick="vanish Hidden('');">
                      Printed brochure</p>
                      <p>
                      <input type="radio"
                      name="receiveVi a"
                      value="byEmail"
                      onclick="vanish Hidden('none');
                      document.forms['myForm'].theAddress.val ue = '';">
                      Via Email</p>
                      <p>Name:<br>
                      <input type="text"
                      name="theName"
                      size="20"><br>< br>
                      Email:<br>
                      <input type="text" name="theEmail" size="20">
                      <br><br>
                      <span id="hideSpan">
                      Postal address:<br>
                      <input type="text" name="theAddres s" size="40">
                      </span>
                      </p>
                      <p>
                      Do you wish to receive additional literature?
                      <br>
                      <input type="radio"
                      name="literatur e"
                      value="yes"
                      onclick="hideHi dden('visible') ";>&nbsp;Yes&nb sp;&nbsp;
                      <!-- use visibility. -->
                      <span id="vanishSpan" >
                      <input type="checkbox"
                      name="gardening "
                      value"gardening ">&nbsp;Gardeni ng
                      <input type="checkbox"
                      name="kitchen"
                      value"kitchen"> &nbsp;Kitche n
                      <input type="checkbox"
                      name="vacation"
                      value"vacation" >&nbsp;Vacati on
                      <!-- Just get it done. I know there are better ways. -->
                      <br>&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
                      &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;
                      <input type="checkbox"
                      name="office"
                      value"office">& nbsp;Office
                      <input type="checkbox"
                      name="secondhom e"
                      value"secondhom e">&nbsp;Sec ond Home
                      </span>

                      <br>
                      <input type="radio"
                      name="literatur e"
                      value="no"
                      onclick="hideHi dden('hidden');
                      var d=document.form s['myForm'];
                      d.elements['gardening'].checked=false;
                      d.elements['kitchen'].checked=false;
                      d.elements['vacation'].checked=false;
                      d.elements['office'].checked=false;
                      d.elements['secondhome'].checked=false; ">
                      No
                      </p>
                      <p><input type="submit"
                      border="0"
                      value="Submit form"
                      width="75"
                      height="17"
                      ALT="Submit button"></p>

                      </form>

                      <script type="text/javascript">
                      // In the case of a reload, the radio button may already be clicked.
                      // This code needs to be after the form.
                      var x = document.forms["myForm"];
                      if (x.receiveVia[0].checked == true)
                      { vanishHidden('' );}
                      else if (x.receiveVia[1].checked == true)
                      { vanishHidden('n one');}
                      else
                      { ;}

                      if (x.literature[0].checked == true)
                      { hideHidden('vis ible');}
                      else if (x.literature[1].checked == true)
                      { hideHidden('hid den');}
                      else
                      { ;}

                      </script>
                      </body>
                      </html>

                      Comment

                      Working...