How to select specific row from database as initially selected in child menu
Have been brewing over this for days.
Two menus let the user choose version and size of a product. With onload (body tag) and onChange (select tag) the child menu only shows available sizes.
I would like to preselect ($row_rssizedefault['size_id']=='4') as initial value in the child menu.
This is the code of the parent menu:
<select class="<?php echo $tmpElementClassVersion; ?> name="SelectVersion" id="SelectVersion" onchange="WA_FilterAndPopulateSubList(rssize_WAJA,MM_findObj('SelectVersion'),MM_findObj('SelectSize'),0,0,false,': ');showprice()">
<?php
do {
?>
<option value="<?php echo $row_rsversion['version_id']?>"<?php if (!(strcmp($row_rsversion['version_id'], $row_rsversion['version']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsversion['version_compound']?></option>
<?php
} while ($row_rsversion = mysql_fetch_assoc($rsversion));
$rows = mysql_num_rows($rsversion);
if($rows > 0) {
mysql_data_seek($rsversion, 0);
$row_rsversion = mysql_fetch_assoc($rsversion);
}
?>
</select>
This is the code of the child menu:
<select class="<?php echo $tmpElementClassSize; ?> name="SelectSize" id="SelectSize" onchange="showprice()">
<?php
do {
?>
<option value="<?php echo $row_rssizedefault['size_id']?>"<?php if (!(strcmp($row_rssizedefault['size_id'], $row_rssize['size']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rssizedefault['size']?></option>
<?php
} while ($row_rssizedefault = mysql_fetch_assoc($rssizedefault));
$rows = mysql_num_rows($rssizedefault);
if($rows > 0) {
mysql_data_seek($rssizedefault, 0);
$row_rssizedefault = mysql_fetch_assoc($rssizedefault);
}
?>
</select>
So far I have managed to preselect the desired value by replacing the selected attribute with this:
<?php if ($row_rssizedefault['size_id']=='4') {echo "selected=\"selected\"";} ?>
but only if I delete this:
onload="WA_FilterAndPopulateSubList(rssize_WAJA,MM_findObj('SelectVersion'),MM_findObj('SelectSize'),0,0,false,': ')"
When I delete the onload code though, the size menu includes all sizes, also a size not available for the version.