Hello I am trying to use this code below. I like the code but I want the default to be DIV Area 1. I have the HTML code showing DIV Area 1 in the drop down menu but I want the Javascript to show DIV AREA 1 by default. What would be the code?
<script type="text/javascript">
$(document).ready(function(){
$('.box').hide();
$('#dropdown').change(function() {
$('.box').hide();
$('#div' + $('#dropdown').val()).show();
});
});
</script>
<form>
<select id="dropdown" name="dropdown">
<option value="0">Choose</option>
<option value="area1" selected="selected">DIV Area 1</option>
<option value="area2">DIV Area 2</option>
<option value="area3">DIV Area 3</option>
</select>
</form>
<div id="divarea1" class="box">DIV Area 1</div>
<div id="divarea2" class="box">DIV Area 2</div>
<div id="divarea3" class="box">DIV Area 3</div>
Or:
Live DEMO
Put one of the above in the DOM ready event:
Or
Full code: (It should answer you next question regarding how to show the selected div…)