I am trying to produce a select box with a specified item being selected and I just can't get it to work. If I look at the source code for the produced web page, the correct option has selected by the side of it, but it is not selected. My PHP code is:
$field = "<select name='frames'".$script.">";
while ($values = db_fetch_array($frame_info)) {
$selected = ($values['frame_type_id'] == $frameid) ? 'selected="selected"' : '';
$field .= "<option value='".$values['frame_type_id']."' ".$selected.">".$values['frame_type']."</option>";
}
$field .= "</select>";
and the html code this produced shows as:
<select name='frames' onchange="changeFrame(this.value)">
<option value='1' >Black</option>
<option value='2' >Bronze</option>
<option value='3' >Colours</option>
<option value='4' >Gold</option>
<option value='5' >Silver and Pewter</option>
<option value='6' >White</option>
<option value='7' >Wood</option>
<option value='8' selected="selected">Wood and Gilt</option>
</select>
but the first option on the list is the one that shows. I've been messing about with this for ages and I just can't see where I'm going wrong
I would appreciate some pointers
thanks
$field = "<select name='frames'".$script.">";
while ($values = db_fetch_array($frame_info)) {
$selected = ($values['frame_type_id'] == $frameid) ? 'selected="selected"' : '';
$field .= "<option value='".$values['frame_type_id']."' ".$selected.">".$values['frame_type']."</option>";
}
$field .= "</select>";
and the html code this produced shows as:
<select name='frames' onchange="changeFrame(this.value)">
<option value='1' >Black</option>
<option value='2' >Bronze</option>
<option value='3' >Colours</option>
<option value='4' >Gold</option>
<option value='5' >Silver and Pewter</option>
<option value='6' >White</option>
<option value='7' >Wood</option>
<option value='8' selected="selected">Wood and Gilt</option>
</select>
but the first option on the list is the one that shows. I've been messing about with this for ages and I just can't see where I'm going wrong
I would appreciate some pointers
thanks
Comment