Web Analytics Made Easy -
StatCounter problem with select box and selected item - CodingForum


No announcement yet.

problem with select box and selected item

  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with select box and selected item

    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>

    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

  • #2
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


    • #3
      it was the javascript

      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