I have a dropdown setting for search. The idea is that you click one option, then OPTGROUP appears. What I would like to do is as soon as the label is selected, it goes to this OPTGROUP section.
I already wrote jQuery. See jsFiddle - So, as soon as you select the main category. I would like optgroup to switch to its paired tag. How can I achieve this?
HTML
<select id="category" name="category"> <option selected="selected" value="0">Choose a category...</option> ... <option value="4">Photography</option> </select> <select multiple="multiple" id="subcategory" name="category_ids[]"> <optgroup label="Art Styles"> <option value="5">Abstract</option> ... <option value="18">Graphics</option> </optgroup> <optgroup label="Art Subjects"> <option value="19">Animals</option> ... <option value="45">Dreams & Nighmares</option> </optgroup> <optgroup label="Media"> <option value="46">Water Colour</option> ... <option value="56">Mixed Media</option> </optgroup> <optgroup label="Photography"> <option value="57">Color Photography</option> ... <option value="64">Celebrity Photography</option> </optgroup>
Portrait Landscape Square
Javascript
// Search Options Dropdown // Hide Subcategory Dropdown $('#subcategory').css('display', 'none'); // Hide Orientation Dropdown $('#orientation').css('display','none'); $('#category').change(function() { $('#subcategory').css('display', 'block'); $('#orientation').css('display', 'block'); var CatValue = $("#category").val(); if (CatValue == '1') { } });
source share