Solved

Displaying certain cells on radio button click

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
USE HTML to redirect a webpage to a local Xcel file. 2 40
Bootstrap input box width 2 33
.php tree directory? 5 55
WordPress Themes 10 34
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

910 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

22 Experts available now in Live!

Get 1:1 Help Now