jquery show/hide options in form

Hello,

I have the following form setup and can not figure out how to make it so when the category is chosen it shows the options relating in the lower select.

I have the jquery library linked on the page FYI.

<form id="select-form">
	<select id="parent-select">
        <option class="options1" value="cat0ne">First Category</option>
        <option class="options2" value="cat2wo">Second Category</option>
        <option class="options3" value="cat3hree">Third Category</option>
    </select>
    <select id="options">
        <option class="option1" value="yuil">This option yuil</option>
        <option class="option1" value="ly">This option ly</option>
        <option class="option2" value="hmfgh">This option hmfgh</option>
        <option class="option3" value="weg">This option weg</option>
        <option class="option1" value="fghjfg">This option fghjfg</option>
        <option class="option2" value="afdg">This option afdg</option>
        <option class="option3" value="erty">This option erty</option>
        <option class="option2" value="ndf">This option ndf</option>
        <option class="option1" value="trhe">This option trhe</option>
        <option class="option2" value="fgh">This option fgh</option>
        <option class="option3" value="ashgh">This option ashgh</option>
        <option class="option3" value="weaf">This option weaf</option>
        <option class="option3" value="asdf">This option asdf</option>
        <option class="option1" value="we">This option we</option>
        <option class="option1" value="fd">This option fd</option>
        <option class="option2" value="fds">This option fds</option>
        <option class="option1" value="asdf">This option asdf</option>
    </select>
</form>

Open in new window

LVL 1
movieprodwAsked:
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.

Rainer JeschorCommented:
Hi,
the following might be a good starting point:
$(document).ready(function() {
    $("#parent-select").change(function() {
        var selectVal = $("option:selected", this).attr("class");
        selectVal = selectVal.replace("options","option");
        $("#options option").each(function() {
            if ($(this).attr("class") == selectVal) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
        // Select first visible option
        //$('#options option:first-child').attr("selected", "selected");
    });
    
});

Open in new window


Live sample:
http://jsfiddle.net/EE_RainerJ/doxg9g2f/

Only open topic is to re-select the first visible element in the remaining options.
HTH
Rainer

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
movieprodwAuthor Commented:
Perfect, thank you
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.