正文

ASP中SELECT下拉菜单同时获取VALUE和TEXT值的实现代码(asp下拉列表框怎么做)难以置信

文章摘要

这篇文章描述了一个使用PHP和JavaScript实现表单自动化填写的案例。主要内容包括: 1. 使用PHP `form action="reguser2.asp" method="post" name="form1"` 实现表单提交。 2. 使用ADODB连接到数据库,通过`select * from zhen`查询获取镇名,并将结果通过下拉选择框显示。 3. 针对ADODB的`recordset`只能获取`value`值的问题,解决了如何获取选中的`text`值。 4. 在JavaScript中,`callvalue()`函数通过`document.form1.zhen.item(index).text`获取选中的`text`值,并将其传递给`hidden`输入字段`sendvalue`。 文章重点介绍了如何在表单自动化中实现数据库数据的获取与传递,提供了解决获取`text`值问题的具体方法。

 <form action=”reguser2.asp” method=”post” name=”form1″ onSubmit=”return checksumit();”> <table width=”100%” border=”1″ cellspacing=”0″ cellpadding=”0″> <tr> <td>所在镇: <% sql=”select * from zhen” set rs=server.createobject(“adodb.recordset”) rs.open sql,conn,3,2 %> <select name=”zhen” id=”zhen”> <option value=-1>选择镇</option> <% if rs.eof and rs.bof then response.Write(“<option value=-1>没有镇</option>”) else do while not rs.eof %> <option value=”<%=rs(“z_id”)%>”><%=rs(“z_name”)%></option> //这里value 和 text 的值 在数据库中获得 ,但变量”zhen” 只能获得value的值…如何获得选中的 text值呢? <% rs.movenext loop end if%> </select></td> </tr> <tr align=”center”> <td><input type=”submit” name=”Submit” value=”下一步” onclick=”Javascript:callvalue()”></td> //第三步,传递到下一页按钮这里增加 onclick取得值 </tr> </table> <input type=”hidden” name=”sendvalue” /> //第一步,这里增加一个hidden的input控件 <script language=”JavaScript”> //第二步,这里写一个获得text值的函数 function callvalue() { sendvalue=document.form1.zhen.item(document.form1.zhen.selectedIndex).text; //alert(sendvalue); document.form1.sendvalue.value=sendvalue; form1.submit(); } </script>