I have a dropdown setup for searching. The idea is you click one option, Then the OPTGROUP appears. What I'd like to do is once the label is selected it jumps to that section of the OPTGROUP.
I have written some jQuery so far. See this jsFiddle - So once you select a main category. I would like the optgroup to go to its paired label. 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')
{
}
});
css()
calls by simpleshow()
andhide()
, without additional arguments. Even if just for readability. – Peafowl- 1
instead of+ 1
, but this would require browser sniffing. – Celenacelene<option>
element. So I'm not sure if it actually makes sense semantically to "move to an optgroup". – Celenacelene