I have a <select>
field, which shows a hidden div on selecting a list item.
There are tree items in the <select>
and each item shows the hidden div.
What I need is when I have selected the 3rd item and I refresh the page, the 3rd item should no longer be selected, but it should change to the 1st item.
I have tried selected="selected"
in the <option>
code but it did not work.
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script>
<script type='text/javascript'>
//<![CDATA[
$(window).load(function(){
$("#column_select").change(function() {
$('div[id^=layout_select]').hide();
$('.'+this.value).show();
});
});
//]]>
</script>
</head>
<body>
<!-- this controls the selection of columns -->
<select name="column_selec" id="column_select">
<option value="col1" selected="selected">1 column</option>
<option value="col2">2 column</option>
<option value="col3">3 column</option>
</select>
<!-- this controls the selection of columns -->
<!-- if '1 column' is selected this div is shown -->
<div id="layout_select1" class="col1">You only have one column!</div>
<!-- if '2 column' is selected this div is shown -->
<div id="layout_select2" class="col2" style="display:none">
<input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay1" '.$layout1.' />imaage1
<input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay2" '.$layout2.' />imaage2 </div>
<!-- if '3 column' is selected this div is shown -->
<div id="layout_select3" class="col3" style="display:none">
<input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay3" '.$layout3.' />imaage3
<input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay4" '.$layout4.' />imaage4
<input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay5" '.$layout5.' />imaage5
</div>
try this code , this will select the first option in the drop down when page will refresh
$(document).ready(function(){
$('#column_select').val('col1');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.