Jump to content

default a value in drop down


jjmusicpro

Recommended Posts

i was pulling a value from mysql, and i wanted to put that value into the drop down.

 

the drop down has 3 values seattle, phoenix, and new york.

 

the value from the drop down is always going to match one pulled from db..

 

so...

 

if the value pulled from the db is say seattle, i wanted seattle to be selected in the drop down menu, but they can change it if they want, i just want it to be selected when they go to the page, with the values that match it form the db

Link to comment
Share on other sites

how do i make it so it wont write out that value again... so

i pull "seattle" form the guys profile, and i make a form that i wanted to edit his info.

 

so the form will have a select drop down box, with 3 values seattle, phoenix, and new york.

 

instead of the drop down box starting off with phoenix or some other place, i wanted it to show the value selected as the one in the db.

Link to comment
Share on other sites

i tried setting an option value as you said but it didnt work

 

<select name=\"payscale\">

<option selected=\"$payscale\"></option>

<option value=\"seattle\">seattke</option>

<option value=\"phoenix\">phoenix</option>

<option value=\"new york\">new york</option>

</select>

Link to comment
Share on other sites

No no.

 

<select name=\"payscale\">
<option selected=\"selected\"></option>
<option value=\"seattle\">seattke</option>
<option value=\"phoenix\">phoenix</option>
<option value=\"new york\">new york</option>
</select>

 

It must be selected="selected"

Link to comment
Share on other sites

something like this:

print "<select name='payscale'>
        <option value='' selected='selected'></option>
while ($row = mysql_fetch_assoc($result){
$city = $row['city'];
print "<option value='$city'>$city</option>\n";
}
print "</select>";

Link to comment
Share on other sites

Try:

 

<?php
$cities = array('seattle','pheonix','new york');//array of cities
//assuming $payscale is the variable containing the state name:
echo '<select name="payscale">';
foreach($cities as $v){
    $selected = '';
    if($v == $payscale){
        $selected = ' selected="selected" ';
    }
    echo '<option value="'.$v.'"'.$selected,'>'.$v.'</option>';
}
echo '</select>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.