Solved

Displaying certain cells on radio button click

Posted on 2011-02-11
5
259 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

729 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