tags:

views:

114

answers:

4

I'm relative new to jQuery and I've been asked to create a hide/show function with a select tag. The function pretty much would be when you click on one of the options in the select tag it will open a div associate with the div of course. To be honest I have no idea how approach this function. I need help urgently, I have already tried many online but none have seem to work. Find below the html code. Thanks.

<div class="adwizard">
                            <select id="selectdrop" name="selectdrop" class="adwizard-bullet">
                                    <option value="adwizard">AdWizard</option>
                                    <option value="collateral">Collateral Ordering Tool</option>
                                    <option value="ebrochure">eBrochures</option>
                                    <option value="brand">Brand Center</option>
                                    <option value="funtees">FunTees</option>
                            </select>
                    </div>

                     <div class="panels">   
                        <div id="adwizard" class="sub-box showhide">
                            <img src="../images/bookccl/img-adwizard.gif" width="95" height="24" alt="AdWizard" />
                            <p>Let Carnival help you grow your business with our great tools! Lor ipsum dolor sit amet. <a href="https://www.carnivaladwizard.com/home.asp"&gt;Learn More</a></p>
                        </div>

                         <div id="collateral" class="sub-box showhide">
                            <p>The Collateral Ordering Tool makes it easy for you to order destination brochures and the sales DVD for that upcoming event. <a href="http://carnival.litorders.com/workplace.asp"&gt;Learn More</a></p>
                        </div>

                        <div id="ebrochure" class="sub-box showhide">
                            <img src="../images/bookccl/img-ebrochure.gif" width="164" height="39" alt="Brochures" />
                            <p>Show your clients that you're listening to their specific vacation needs by delivering relevant planning info quickly.  <a href="http://productiontrade.carnivalbrochures.com/start.aspx"&gt;Learn More</a></p>
                        </div>

                         <div id="brand" class="sub-box showhide">
                            <p>Carnival Brand Center is where you'll find information on our strategy, guidlines, templates and artwork.   <a href="https://carnival.monigle2.net/user_info.asp?login_type=agent"&gt;Learn More</a></p>
                        </div>

                        <div id="funtees" class="sub-box showhide">
                            <img src="../images/bookccl/img-funtees.gif" width="164" height="39" alt="Funtees" />
                            <p>Create your very own Fun Design shirts to commemorate that special occasion aboard a Carnival "Fun Ship!"  <a href="http://carnival.victorydyo.com/"&gt;Learn More</a></p>
                        </div>
                    </div><!-- ends .panel -->
                    <a class="view" href="#">See All Marketing Tools</a>
                </div>
+1  A: 
$(document).ready(function() {
    $('#selectdrop').change(function() {
        $('.panels div').hide();
        var panel = $(this).val();
        $('#' + panel).show();
    });
});

Untested, but I think that'll work ... it's very rough, but a jumping off point, and can most definitely be done better.

Nathan Loding
+2  A: 

I took your code above and made a jsfiddle with (I believe) the functionality you were looking for.

Nate Pinchot
i think this update to your code is more complete.. http://jsfiddle.net/fbcS9/3/
Gaby
It was close but not the effect I'm looking for. I need one of the options to be opened and the others to be closed until they are clicked,
Ozzy
Yea, I realized I missed the hide after I first saved it. Thanks for fixing :) Updated to your link in the answer.
Nate Pinchot
@Gaby thank you so much I'd in debt to you all my life it works beautifully.
Ozzy
@Nate Pinchot, thanks to you too man, you guys saved my life
Ozzy
wow, saved his LIFE! awsome!
Mark Schultheiss
Now if I could only save the princess...
Nate Pinchot
lol ... feels good... never saved someones life before :)
Gaby
A: 

Or better

<head>
<script>
$(document).ready(function() {
    $('.panels div').hide();// << IMPORTANT
    $('#selectdrop').change(function() {
        $('.panels div').slideUp();
        var panel = $(this).val();
        $('#' + panel).slideDown();
    });
});
</script>
</head>
<body>
.. The page ..
</body>
Neb
The problem with this one is that I need to have one of the divs selected. But works perfect.
Ozzy
@OzzyThen good, didn't work for me :P
Neb
A: 

DEMO: http://jsbin.com/amoto4

CSS: .panels div { display:none }

JQUERY:

$(function() {
    $('.panels div:eq(0)').show();
    $('#selectdrop').change(function() {      
      $('#' + this.value ).show().siblings().hide();
    });
});​​​
aSeptik