Hello!

I have an update page where I have a dropdown menu with some options.

The problem I have, is that I would like to get in that menu the actual value of the register I want to update instead of the "Initially Selected" option of the menu.

Lets say:

<select name="menu" size="1" id="select">
<option value="" selected>Select an option</option>
<option value="Cars">Cars</option>
<option value="Planes">Planes</option>
</select>

In this menu the Initial value is "select an option". How can I automatically get in the menu the option 2 and 3 depending the Data base?

Any help will be appreciated!

Thank you

    Easiest way to do this is to give each option a value. Possibly create another table in the db for it, or even just create a simple global array that never changes. It's up to you really. Then all you need to do is loop through each of those select options, check it against the database value, and if it's selected, add a selected="true" to it, if not, just print it without that. Pointless example:

    while ( $option = @mysql_fetch_array($option_query, MYSQL_ASSOC) )
    {
        if ( $option['id'] == $user['option_id'] )
        {
            $select = " select='true'";
        }
    
    else
    {
        $select = "";
    }
    
    echo ( "<option value='".$option['val']."'".$select.">".$option['title']."</option>" );
    }
    

    You get the idea?

      True, except for one thing... for an option to be selected, you must use "selected='selected'"

        Uh...I must've missed that somewhere, because I was always under the impression it was kind of like the "multiple" indicator for these. It doesn't NEED to have anything after it, but the new validators require you to put something like "true" or "selected" or "yes" with it. If it is, I've missed it, and honestly don't mind too much. When it stops working with "='true'", I'll thank you for telling me how to fix it, but until then, I'll try my damndest to stay away from W3C and it's crap. nods sagely

          I'll try my damndest to stay away from W3C and it's crap. nods sagely

          LOL... are you the anti-standards guru? You should get along famously with goldbug 😃

            I won't go so far as to call myself a guru...buuuut, I will say I'm horribly anti-standard. I can sum up my argument with one simple tag...

            <br />

            That tag there is sheer and utter stupidity, and the first thing that made me sour about w3c and their standards. Learn your Magic, and you'll know that the Cheese Stands Alone...and so doe the <br> tag...don't need no stinking slashes!

            And for added effect, thanks to a new friend who reminded me of this...my favorite bedtime story...

            http://home.cc.umanitoba.ca/~galkarb/000581.html

              Write a Reply...