简体   繁体   中英

phprunner drop-down list -default value

I have a drop-down list of US states in my db. Each record has details of the user etc. now when i try to edit the user details, the drop-down list should retain the original value of the state but it says "Please select". The whole purpose to do this is to make sure the state is not changed automatically.

This is what I have

//create dropdown box 
$str = ""; 
$str.= "<select onchange=\"window.location.href=this.options[this.selectedIndex].value;\"><optio‌​n value=\"\">Please select</option>"; 

//select values from database 
global $conn; 
$strSQL = "select states from states"; 
$rs = db_query($strSQL,$conn); 
while ($data = db_fetch_array($rs)) 
 $str.="<option value=\"states_list.php?a=search&value=1&SearchFor=".$data["selected"]."&SearchO‌​ption=Contains&SearchField=company\">".$data["selected"]."</option>"; 

$str.="</select>"; 
echo $str;

You need to have the code put in a

selected="selected"

in the <option> tag of the state option that should be selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM