...

View Full Version : problem with select box and selected item



kickboxinghelen
09-07-2011, 03:46 PM
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

Fou-Lu
09-07-2011, 04:33 PM
This has nothing to do with PHP nor HTML from the looks of it. So it falls against one of two things: either that JS that you have in use, or the browser that is used to render it.
The PHP successfully creates the option tag with the appropriate SELECTED option, and the HTML properly constructs it. The problem lies elsewhere.

kickboxinghelen
09-08-2011, 10:49 AM
Yes your right it was something else. I was getting the selected value from a session variable but when I changed the value, I'd forgotten to write the new value to the session variable. I was so convinced I must be doing the select box wrong, I didn't think to look anywhere else.

Thanks a lot, you've saved lots of hair pulling ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum