<select id="category"> <option value="" disabled="disabled" selected="selected" onchange="hideshow(this)">Please select a category</option> <option name="choice1" value="divPie"> Pie </option> <option name="choice2" value="divCake"> Cake </option> <option name="choice2" value="divCake"> Candy </option> </select>
All divs are hidden because when the user selects an element, at that time the div will display
<div id="divPie" class="food" style="display:none"> <p> this is pie </p> </div> <div id="divCake" class="food" style="display:none"> <p> this is pie </p> </div> <div id="divCandy" class="food" style="display:none"> <p> this is pie </p> </div>
This is javascript code that shows a div when a user selects a value from a div
<script> function hideshow(divval) { $("#"+divval).show(); } </script>
Let me know if you have any problems, this is not a verified script, but I think it works
source share