I have five dropdown list which depending on the selection the display changes to block.
The problem comes when values are posted back. The drop down list does not show the values. This likely because of javascript that by default displays as none the drop down list. The javascript listens for onclick. Here is part of the javascripts:
function changeOptions() {
var form = window.document.getElementById("frm1");
var sv = window.document.getElementById("sv");
var sv2= window.document.getElementById("sv2");
var sv3 = window.document.getElementById("sv3");
var sv4= window.document.getElementById("sv4");
var sv5 = window.document.getElementById("sv5");
if (form.radioButton1.checked) {
sv2.style.display = "none";
sv3.style.display = "none";
sv4.style.display = "none";
sv5.style.display = "none";
sv.style.display = "block";
//sv.selectedIndex =0;
else if (form.radioButton5.checked) {
sv.style.display = "none";
sv2.style.display = "none";
sv3.style.display = "none";
sv4.style.display = "none";
sv5.style.display = "block";
sv5.selectedIndex = 0;
}
}
window.document.getElementById("radioButton5").onclick = changeOptions;
The dropdown menu is populated from my database. Below is the code. There are five of them The display:none changes to block depending which radio button is clicked.
<select style="width:200px; **display:none**" name="pGroup" id="sv" >
<option value="Choose an Option" >Choose Product Group</option>
<?php
$selGroup = isset($_GET['pGroup'])?$_GET['pGroup']:"";
$sql="SELECT DISTINCT pGroup FROM cr39 WHERE ";
$sql.="HeadingNo = 3 ORDER BY pGroup ASC";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option <?php if($data['pGroup'] == $selGroup) echo 'selected="selected"'; ?> value ="<?php echo $data['pGroup'] ?>" ><?php echo $data['pGroup'] ?></option>
<?php } ?>
</select>
.
.
.
.
<select style="width:200px; **display:none**" name="pGroup5" id="sv5">
<option value="Choose an Option" >Choose Product Group</option>
<?php
$selGroup = isset($_GET['pGroup5'])?$_GET['pGroup5']:"";
$sql="SELECT DISTINCT pGroup FROM cr39 WHERE ";
$sql.="HeadingNo = 7 ORDER BY pGroup ASC";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option <?php if($data['pGroup'] == $selGroup) echo 'selected="selected"'; ?> value ="<?php echo $data['pGroup'] ?>" ><?php echo $data['pGroup'] ?></option>
<?php } ?>
</select>
I am a novice in this and would like help on how to retain the value on my dropdownon postback.
per comment above, would need to see more code to be exact, but here is a pseudo version that you may be able to adapt;
replace
$_GET['selectedGroupId']with your fieldname/idsee if that gets you on the right track