Solved

Displaying certain cells on radio button click

Posted on 2011-02-11
5
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

733 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