日期:2014-05-17  浏览次数:20783 次

asp+javascript 取值得问题!进来看看
有两个文本框,分别是学号和姓名   ,输入数据的时候,我想让输入学号,姓名文本框中就出现这个学生相应的名字,输入名字的时候,学号自动出现在学号文本框中,需要如何实现,大家能够举个例子!

表A

xuehao     name
00030       张三
00031       李四


------解决方案--------------------
查询结果页TEST.ASP
<script language= "JavaScript ">
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version > = 5)
try {
xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP ");
} catch (e) {
try {
xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP ");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != 'undefined ')
{
xmlHttp = new XMLHttpRequest();
}

function callServer() {
var xuehao = document.getElementById( "xuehao ").value;
var url = "view.asp?xuehao= " +xuehao ;
xmlHttp.open( "GET ", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);}

function updatePage() {
document.getElementById( "name ").value= '正在查询.... '
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById( "name ").value = response;
}
}

</script>
<body>
<p>
<input name= "xuehao " type= "text " id= "xuehao " />
<input type= "submit " name= "Submit " value= "提交 " onclick= "javascript:callServer(); " />
</p>
<p>
<input name= "name " type= "text " id= "name " />
</p>


读数据页 VIEW.ASP
<%
Response.Charset = "gb2312 "
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.cachecontrol = "no-cache "

xuehao=request( "xuehao ")
sql= "select name from 表A where xuehao= ' "&xuehao& " ' "
set rs=server.createobject( "adodb.recordset ")
rs.open sql,conn,1,1
if rs.eof then
response.write "没有查询到数据! "
else
response.write rs( "name ")
rs.close
set rs=nothing
end if
%>
------解决方案--------------------
方法如下:

  1.将用户名和编到数组里:

<html>

<head>

    <%= " <script language=javascript> "%>

var arr_emp=new Aarray()

<%
set rs=server.create( "adodb.recordset ")

rs.open "select * from emp ",conn,1,3

i=0

do while not rs.eof

%>
arr_emp.Options( <%=i%> )=New Option( " <%=rs( "emp_no ")%> ", " <%=emp_name%> ")

<%
i=i+1

rs.movenext
loop
%>

function show_emp_name(obj_emp_no)

{
for(var i=0; i <= arr_emp.length; i++)

{
if (arr_emp[i][0]==obj_emp_no.value)

{

document.frm_test.emp_name.value=arr_emp[i][1]

break;