保持选择列表的值 [英] Keep value of select list

查看:52
本文介绍了保持选择列表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于查询的选择列表。它将结果发布到同一页面。



但是,即使更新页面后,列表中的选项也会返回到列表的顶部,而不是我已选择。



在选择框中保留该选项的最简单方法是什么?



我我们在网上看到过例子,但它们都是指输入的选项,而不是查询列表,我无法弄清楚如何使代码适应查询列表。



我已经在下面列出了相关代码。



我尝试了什么:



I have a Select list based on a query. It posts the results to the same page.

However, even after updating the page, the choice in the list returns to the top of the list, rather than what I had selected.

What is the simplest way to retain that choice in the select box?

I have seen examples online, but they all refer to typed-in options, not a query list, and I can't figure out how to adapt the code to a query list.

I have included the relevant code below.

What I have tried:

<form action="http://www.pabirds.org/joomla/index.php/birding/birds-of-pa" method="post" name="form1" target="_self" id="form1">
<label for="Species" class="MediumSerifText">Select Species (Alphabetical order):</label>
<select name="Species" id="Species" onchange="this.form.submit()">
<?php
do {  
?>
        <option value="<?php echo $row_rsSelectSpeciesAlpha['ID']?>"><?php echo $row_rsSelectSpeciesAlpha['CommonName']?></option>
        <?php
} while ($row_rsSelectSpeciesAlpha = mysql_fetch_assoc($rsSelectSpeciesAlpha));
  $rows = mysql_num_rows($rsSelectSpeciesAlpha);
  if($rows > 0) {
      mysql_data_seek($rsSelectSpeciesAlpha, 0);
	  $row_rsSelectSpeciesAlpha = mysql_fetch_assoc($rsSelectSpeciesAlpha);
  }
?>
</select>

</form>

推荐答案

row_rsSelectSpeciesAlpha ['ID']?>>< ;?php echo
row_rsSelectSpeciesAlpha['ID']?>"><?php echo


row_rsSelectSpeciesAlpha ['CommonName']?>< / option>
<?php
} while(
row_rsSelectSpeciesAlpha['CommonName']?></option> <?php } while (


row_rsSelectSpeciesAlpha = mysql_fetch_assoc(
row_rsSelectSpeciesAlpha = mysql_fetch_assoc(


这篇关于保持选择列表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆