Solved

Displaying certain cells on radio button click

Posted on 2011-02-11
5
253 Views
Last Modified: 2012-05-11
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
Comment
Question by:BrighteyesDesign
  • 2
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 34868930
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
 
LVL 12

Expert Comment

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

and vice versa
0
 

Author Comment

by:BrighteyesDesign
ID: 34868978
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
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34868996
how can they be 'options' and be 'mandatory'?

It looks like a design issue to me.

0
 

Author Closing Comment

by:BrighteyesDesign
ID: 34869023
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now