<选择>下拉列表默认值 [英] <select> dropdown default value
问题描述
我有这个代码:
if(isset($ _ POST ['search']))
{
$ res1 = mysql_query(SELECT * FROM aircraft where acode ='$ _POST [ac]')or die(mysql_error());
while($ row = mysql_fetch_array($ res1))
{
$ airc = $ row ['acode'];
$ amode = $ row ['amodel'];
$ stat = $ row ['status'];
$ rem = $ row ['remarks'];
echo< center>< table>< form name = \frmMain\method = \post\>
< tr>< ; td>< font face = consolas>< b>飞机代码:< / b>< / font>< / td>< td>< input type = text name = arc value ='$ airc 'readonly = readonly>< / td>< / tr>
< tr>< td>< font face = consolas>< b>飞机型号:*< / b>< /字体>< / td>< td>< input type = text name = am value ='$ amode'>< / td>< / tr>
< tr>< td> < font face = consolas>< b>状态:*< / b>< / font>< / td>< td>< input type = text name = st value ='$ stat'> < / td>< / tr>
< tr>< td>< font face = consolas>< b>备注:*< / b>< / font>< / td> ;< td>< input type = text name = rm value ='$ rem'>< / td>< / tr>< / table>;
}
}
在提交搜索按钮时,此代码显示数据来自飞机台。允许用户使用(*)符号更新数据。
由于默认情况下的状态(可用,不可用),我更改了此
< tr>< td>< font face = consolas>< b>状态:*< / b>< / font>< / td>< td>< input type = text name = st value ='$ stat'>< / td>< / tr>
< tr>< td>< font face = consolas>< b>状态:*< / b>< / font>< ; / td>< td>< select name = st>
< option value = Available> Available< / option>
< option value ='不可用'>不可用< / option>
< / select>< / td>< / tr>
但是我想让下拉菜单设置为默认值取决于 $ stat = $ row ['status'];
,因为这是一个更新表单。如果正在检索的数据的状态为可用,则下拉列表的默认值为可用。我该如何实现呢?我试过< select name = status value ='$ stat'>
,但它不起作用。任何帮助将不胜感激。谢谢!
只需将 selected =selected
您的 $ row ['status']
,
<选项=selectedvalue =available> Available< / option>
I have this code:
if(isset($_POST['search']))
{
$res1=mysql_query("SELECT * FROM aircraft where acode = '$_POST[ac]'") or die(mysql_error());
while($row=mysql_fetch_array($res1))
{
$airc=$row['acode'];
$amode=$row['amodel'];
$stat=$row['status'];
$rem=$row['remarks'];
echo "<center><table><form name=\"frmMain\" method=\"post\">
<tr><td><font face=consolas><b>Aircraft Code:</b></font></td><td><input type=text name=arc value='$airc' readonly=readonly></td></tr>
<tr><td><font face=consolas><b>Aircraft Model:*</b></font></td><td><input type=text name=am value='$amode'></td></tr>
<tr><td><font face=consolas><b>Status:*</b></font></td><td><input type=text name=st value='$stat'></td></tr>
<tr><td><font face=consolas><b>Remarks:*</b></font></td><td><input type=text name=rm value='$rem'></td></tr></table>";
}
}
On submit 'search' button, this code displays the data from aircraft table. The user is allowed to update the data with the (*) sign.
Since the Status are the following by default (Available, Not Available), I changed this
<tr><td><font face=consolas><b>Status:*</b></font></td><td><input type=text name=st value='$stat'></td></tr>
to this,
<tr><td><font face=consolas><b>Status:*</b></font></td><td><select name=st>
<option value=Available>Available</option>
<option value='Not Available'>Not Available</option>
</select></td></tr>
But I want the dropdown to have it's default value depending on $stat=$row['status'];
since this is an update form. If the data being retrieved has it's status 'Available', then the dropdown should have it's default value as 'Available'. How can I achieve that? I tried <select name=status value='$stat'>
but it doesn't work. Any help will be appreciated. Thanks!
Just put selected="selected"
on the option depending on your $row['status']
,
<option selected="selected" value="available">Available</option>
这篇关于<选择>下拉列表默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!