刷新后将 html 下拉列表设置为选定值
刷新后如何将下拉菜单设置为获取变量。有一个 html 菜单,刷新后我希望将下拉菜单设置为选择变量。例如,如果我从菜单中选择 3,然后单击“提交”,下拉列表应显示 3。我曾经使用文本框执行此操作,在文本框中将值设置为 get 变量,我只是尝试使用 html 下拉菜单执行相同的技术。
</select>
<?php
$c=$_GET['c'];
$p=$_GET['p'];
$id=$_GET['id'];
if ($c!=NULL){
$sq=mysql_query("SELECT * FROM ps WHERE b='$id' AND c='$c'");
while ($row=mysql_fetch_assoc($sq)) {
$start=$row['start'];
$start=trim($start);
$m=$row['m'];
}
echo "<select type='text' name='pro' id='amount' value= '$p'>";
echo "<option value=''>P</option>";
while ($start<=$m){
echo "<option value='$start'>$start</option>";
$start++;
}
}
?>
</select>
how do i set a dropdown menu to a get variable after refresh. there is an html menu and after a refresh i would like the dropdown to be set to the select variable. for example if i select 3 from the menu then click submit the dropdown should display 3. i used to do this with textboxes where i would set the value to the get variable im just trying to do this same technique with html dropdown menus.
</select>
<?php
$c=$_GET['c'];
$p=$_GET['p'];
$id=$_GET['id'];
if ($c!=NULL){
$sq=mysql_query("SELECT * FROM ps WHERE b='$id' AND c='$c'");
while ($row=mysql_fetch_assoc($sq)) {
$start=$row['start'];
$start=trim($start);
$m=$row['m'];
}
echo "<select type='text' name='pro' id='amount' value= '$p'>";
echo "<option value=''>P</option>";
while ($start<=$m){
echo "<option value='$start'>$start</option>";
$start++;
}
}
?>
</select>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个表格吗?如果是这样,您会回显如下选项:
但首先您需要提交表单。
这个想法是,将此 select 元素的设置变量的值与循环内 $start 的当前值进行比较,如果匹配则打印“selected”。
Is this in a form? If so you echo options like this:
But first you need to submit the form though.
The idea is that you compare the value of a set variable for this select element to current value of $start within the loop, and print 'selected' if they match.
这是你的意思吗??
http://www.plus2net.com/php_tutorial/pb-drop.php
Is this what you meant??
http://www.plus2net.com/php_tutorial/pb-drop.php