Show Hide multiple div tags from multiple radio buttons

Hi,
I have the following jquery code snip that shows or hides a DIV based on a radio button selection which is great for 2 radio buttons. Problem is I now have 10 radio buttons, while I could write the if / else for each radio button and div it seems like a lot of code to do something simple. Is there an easy way to accomplish this for 10 radio buttons / divs.

<script type="text/javascript">
        $(document).ready(function () {

            $("input[name$='choosecanvassize']").click(function () {

                var radio_value = $(this).val();

                if (radio_value == 'rect10x8') {
                    $("#yesbox").show("slow");
                    $("#nobox").hide();
                }
                else if (radio_value == 'rect14x8') {
                    $("#nobox").show("slow");
                    $("#yesbox").hide();
                }
            });

            $("#yesbox").hide();
            $("#nobox").hide();
        });
</script>

Open in new window


Thanks
nl
LVL 2
nedloganAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roman GhermanSenior Software EngineerCommented:
I see depending on the radiobutton you perform different actions. what action are you going to perform for other radiobuttons?
0
nedloganAuthor Commented:
Show other divs. There are 10 radio buttons and depending on which one is clicked the user will see 1 of 10 divs containing some content.
nl  
0
Roman GhermanSenior Software EngineerCommented:
the best you can do here I think is:

 
 var radio_value = $(this).val();

                 $("#nobox, #yesbox").hide();

                if (radio_value == 'rect10x8') {
                    $("#yesbox").show("slow");
                }
                else if (radio_value == 'rect14x8') {
                    $("#nobox").show("slow");
                }
                else if (radio_value == 'anotherrbtn') {
                    $("#anotherrbtnBOX").show("slow");
                }

Open in new window


THis is all that I can think about.
Otherwise if you have an array that would map radio_value with the div id then it would be easier
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nedloganAuthor Commented:
Hi,
Ok, well that seems to work, I can't be bothered with arrays at the moment. Thanks for your help.
Regards,
NL
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.