填充基于使用经典的ASP下拉列表中选择选项在网页领域 [英] Populate fields in webpage based on option selected from a drop down list using Classic ASP

查看:357
本文介绍了填充基于使用经典的ASP下拉列表中选择选项在网页领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,有一个下拉组合框中选择一个页面,该值这是从数据库中来。旁边的组合框有两个文本框。

I have a page that has a drop down combo box, the values for which are coming from a database. next to the combo box are two text boxes.

现在的基础上,从下拉列表中选择的选项,我需要去到数据库,并从数据库获取相关数据并填充两个文本框。

now based on the option selected from the drop down list, I need to go to the DB and get relevant data from the db and populate the two text boxes.

有在那些直线前进的页面等领域,但我不知道如何去这种情况。

There are other fields in the page that are straight forward, but i don't know how to go about with this situation.

任何链接/样品code /阅读材料/或帮助任何其他形式将大大AP preciated。

any link/sample code/reading material / or any other form of help will be greatly appreciated.

谢谢,

好吧我想到这里大声,这里的样品code
    

Ok am thinking loud here, here's the sample code

   <%
    While not rsRecordSet.EOF
    %>
    <OPTION VALUE="<%=rsRecordSet("FldID")%>"><%=rsRecordSet("FldName")%></OPTION>
    <%
    rsRecordSet.MoveNext
    Wend
    Set rsRecordSet= nothing
    %>

我需要的价值,即FLDID作为参考来选择的数据,但如果我能某处标签中的数据的其余部分。例如其他两个字段需要显示FldAge和FldGender。我可以得到那些在rsRecordSet,并且因为我填充选项我可以填充一些标签和一些如何调用它后来根据从下拉列表中选择的选项。只是在想大声这里。谢谢,S

I need the Value i.e. FldID as the reference to the data selected, but if i can tag the rest of the data somewhere. e.g. the other two fields need to show FldAge and FldGender. I can get those in the rsRecordSet, and as i am populating the Option i can populate some tag and some how call it later depending on the option selected from the combo. Just thinking loud here. Thank,s

推荐答案

当然也有不少方法可以做到这一点。当您选择一个选项,然后显示的年龄和性别这个例子将提交表单。 (查询,连接等将需要改变,以适应你的对象)

There are of course quite a few ways to do this. This example will submit the form when you select an option then display the age and gender. (query, connection, etc will need to be changed to suit your objects)

<form action="" method="get">
    <select name="id" onchange="this.form.submit()">
<%
While not rsRecordSet.EOF
%>
        <OPTION VALUE="<%=rsRecordSet("FldID")%>"><%=rsRecordSet("FldName")%></OPTION> 
<% 
    rsRecordSet.MoveNext 
Wend 
Set rsRecordSet= nothing 
%>
    </select> 
</form>
<%
If Request.QueryString("id") <> "" Then
'Open recordset to retrieve age and gender
rsRecordSet2.Open "SELECT FldAge, FldGender FROM table WHERE FldID = " & CInt(Request.QueryString("id")), connection
If Not rsRecordSet2.EOF Then
%>
    Age: <%= rsRecordSet2("FldAge") %><br />
    Gender: <%= rsRecordSet2("FldGender") %><br />
<%
End If
rsRecordSet2.Close
Set rsRecordSet2 = Nothing
%>

这是更好地做这种与AJAX的东西,这是很容易,即使在传统的ASP做的,特别是如果你可以使用jQuery。我可以发布一个例子,如果你愿意走这条路。

It is better to do this sort of thing with AJAX, and this is easy to do even in Classic ASP, particularly if you can use jQuery. I can post an example if you would like to go this way.

更新与Ajax解决方案:

好吧,这里是使用jQuery我recommedn你在做的JavaScript Ajax的使用会带我太长时间的例子...

Okay, here is an example using jQuery which I recommedn you to use as doing Ajax in JavaScript will take me too long...

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#id").change(function() {
            $.get('ajax.asp?id='+$("#id").val(), function(data) {
                var fields = data.split(',');
                $("#age").html(fields[0]);
                $("#gender").html(fields[1]);
            }); 
        });
    });
</script>

<select id="id">
<%
While not rsRecordSet.EOF
%>
    <OPTION VALUE="<%=rsRecordSet("FldID")%>"><%=rsRecordSet("FldName")%></OPTION>
<%
    rsRecordSet.MoveNext
Wend
Set rsRecordSet= nothing
%>
</select>
<div id="age"></div>
<div id="gender"></div>

创建一个名为ajax.asp脚本。您需要添加所有的数据库连接的东西在里面。然后打开基于传递的ID的记录,并返回年龄和性别作为一个逗号分隔的字符串,如:

Create a script called ajax.asp. You will need to add all your database connection stuff in there. Then open a recordset based on the ID passed and return the age and gender as a comma separated string, like this:

<%
'Open recordset to retrieve age and gender 
rsRecordSet2.Open "SELECT FldAge, FldGender FROM table WHERE FldID = " & CInt(Request.QueryString("id")), connection 
If Not rsRecordSet2.EOF Then 
    Response.Write(rsRecordSet2("FldAge") & "," & rsRecordSet2("FldGender"))
End If 
rsRecordSet2.Close 
Set rsRecordSet2 = Nothing 
%> 

这篇关于填充基于使用经典的ASP下拉列表中选择选项在网页领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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