Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 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>
    </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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •