• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Displaying certain cells on radio button click

I have form set up so that when someone selects a radio button certain options appear and if they click the other radio buttons others appear.

This is done by assigning the cell a class of 'display' or 'nodisplay' and the following CSS

<style>
.display {
display : block;
}
.noDisplay {
display : none;
}
</style>

My problem is that when you click radio button A the info shows but then when you select radio button B this info shows and the 'A' options do not dissapear.

If rbA is selected rbA options show then when rbB is selected rbA options should not display and vice versa.

I know this may be confusing so here's the live page (it's the last question) http://www.hal-locate.eu/register.html.


Where did you purchase your motorhome? *</span><br />
                                                <span id="sprytextfield12">
                                                  <input name="where" type="text" class="inputhi" id="where" size="45" />
                                                  <span class="textfieldRequiredMsg">This  is required.</span></span></td>
  </tr>
                                            <tr>
                                              <td class="copy">Motorhome registration number*<br />
                                                <span id="sprytextfield13">
                                                  <input name="registration" type="text" class="inputhi" id="registration" size="45" />
                                                  <span class="textfieldRequiredMsg">This is required.</span></span></td>
  </tr>
                                            <tr>
                                              <td><p>VIN Number (motorhome only)*</p>
                                                <span id="sprytextfield16">
                                                  <input name="vin" type="text" class="inputhi" id="vin" size="45" />
                                                  <span class="textfieldRequiredMsg">This is required.</span></span></td>
  </tr>
                                            <tr>
                                              <td><p>Make*</p>
                                                <span id="sprytextfield17">
                                                  <input name="vin2" type="text" class="inputhi" id="vin2" size="45" />
                                                  <span class="textfieldRequiredMsg">This is required.</span></span></td>
  </tr>
                                            <tr>
                                              <td><p>Model*</p>
                                                <span id="sprytextfield18">
                                                  <input name="model" type="text" class="inputhi" id="model" size="45" />
                                                  <span class="textfieldRequiredMsg">This is required.</span></span></td>
  </tr>
                                            <tr>
                                              <td><p>Colour/unique identifiers*</p>
                                                <span id="sprytextfield19">
                                                  <input name="colour" type="text" class="inputhi" id="colour" size="45" />

Open in new window

0
BrighteyesDesign
Asked:
BrighteyesDesign
  • 2
  • 2
1 Solution
 
Gurvinder Pal SinghCommented:
replace line 317 to 326 by

<tr>
      <td width="25%" align="left">
            <p>Do you own a:<br />
                  <script>
                        function resetNToggle(divId)
                        {
                              document.getElementById("homeStay").setAttribute("class", "noDisplay");
                              document.getElementById("motorhomechoice").setAttribute("class", "noDisplay");

                              document.getElementById(divId).setAttribute("class", "display");
                        }
                  </script>
                  <input name="corm" type="radio" value="Caravan" onclick="resetNToggle('homeStay');"/>
                        Caravan or
                  <span class="homewording">
                        Motorhome
                                <input name="corm" type="radio" value="Motorhome" onclick="resetNToggle('motorhomechoice');"/>
                        </span>
                        <label for="checkbox"></label>
                </p>
      </td>
</tr>

0
 
enachemcCommented:
                                        <input name="corm" type="radio" value="Caravan" onclick="document.getElementById('homeStay').className = 'display';"document.getElementById('motorhomechoice').className = 'noDisplay';"/>

and vice versa
0
 
BrighteyesDesignAuthor Commented:
Thanks to both of you,

Works great Gurvinder. I'm sure yours does to enachemic I just tried Gurvinders first!

I'll ask this as a separate question if it's a bit too involved but...

There are compulsory fields on both sets of options. Now of course the form does not submit because the 'hidden' options are not filled in.

Do you know a way round this?

0
 
Gurvinder Pal SinghCommented:
how can they be 'options' and be 'mandatory'?

It looks like a design issue to me.

0
 
BrighteyesDesignAuthor Commented:
Basically the site is for a caravan/motorhome securtiy device.

A user selects if they have a caravan or motorhome.

The caravan owners have to fill in details specific to caravans and the motorhome users likewise.

So even though it's an option it is compulsory.

Now worries though, i'll figure this one out
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now