这是典型的ajax应用呀,当select onchange里执行一个ajax请求ajax请求,发送select的值,从数据取结果。在ajax请求的回调里给input赋返回值ok

解决方案 »

  1.   

    我也明白啊, 但是就是不太会ajax啊不过我找到其他方法代替了
      

  2.   

    不用ajax可以用iframe实现
    需要的话,我可以写代码
      

  3.   

    -=test.asp=-<select name="select" onchange="Send_s();">
      <option selected="selected" id="s1">A</option>
      <option id="s2">B</option>
      <option id="s3">C</option>
    </select>
    <input ID="text1" name="textfield" type="text" style="font-size:14" size="5" maxlength="5" />
    <iframe id="myif" width="0" height="0" style="visibility:hidden" ></iframe>
    <script language="javascript">
    function Send_s(){
    if (s1.selected==true){
    document.getElementById('myif').src = "iframe.asp?s=" + s1.innerText + "&" +new Date();
    }
    if (s2.selected==true){
    document.getElementById('myif').src = "iframe.asp?s=" + s2.innerText + "&" +new Date();
    }
    if (s3.selected==true){
    document.getElementById('myif').src = "iframe.asp?s=" + s3.innerText + "&" +new Date();
    }
    }
    function Get_s(s){
    document.all.text1.value=s;
    }</script>-=iframe.asp=-
    <% 
    t=request("s")
    arr= array("A1","B1","C1")
    if t="A" then s=arr(0)
    if t="B" then s=arr(1)
    if t="C" then s=arr(2)
     %>
    <script>
    var s="<%= s %>";
    window.parent.Get_s(s);
    </script>
      

  4.   

    不好意思,这些("A1","B1","C1")是存在数据库中,而且这些值是在不断改变,所以需要用数据库保存,你能不能帮我按照数据库方式写吗?可以吗?谢谢
      

  5.   

    conn为你的数据库连接文件,如果没有,可以用我这个,数据库表名作为ABC
    修改iframe.asp为
    -=iframe.asp=-
    <!--#include file="conn.asp"-->
    <% 
    t=request("s")'获取参数s,数据库表名为ABC
    sql="select * from ABC where B='"&t&"'"
    set rs=conn.execute(sql)
    s=rs("C")
     %>
    <script>
    var s="<%= s %>";
    window.parent.Get_s(s);
    </script>
    -=conn.asp=-
    <%dim connstr
    dim conn
    '下边是数据库路径
    dbname="data.mdb"
     
    connstr = "DBQ=" + server.mappath(dbname) + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"       
    set conn=server.createobject("ADODB.CONNECTION")

    if err.number<>0 then 
    err.clear
    set conn=nothing
    response.write "数据库连接出错!"
    Response.End
    else
    conn.open connstr
    if err then 
    err.clear
    set conn=nothing
    response.write "数据库连接出错!"
    Response.End 
    end if
    end if   

    sub endConnection()
    conn.close
    set conn=nothing
    end sub

    %>
      

  6.   

    不好意思,再问一下,这个功能能不能在test.asp页面内完成,而不需要iframe.asp,不知是否可以实现?再次谢谢你的帮助
      

  7.   

    这实际是比较常用的原始iframe免刷新机制的实现,
    他就上靠刷新隐藏的iframe中的iframe.asp页面开获取服务器信息,从而实现test.asp的免刷新,所以不能去掉iframe.asp和iframe框架,不过我建议你学习一下ajax,这个老技术实现的比较新的技术,现在比较流行,而且很方便.
      

  8.   

    <select onchange="document.all.reInput.value=this[this.selectedIndex].re">
    <option value="" re=""></option>
    <option value="1" re="A1">A</option>
    <option value="2" re="B1">B</option>
    <option value="3" re="C1">C</option>
    <option value="4" re="D1">D</option>
    <option value="5" re="E1">E</option>
    </select>
      

  9.   

    <select onchange="document.all.reInput.value=this[this.selectedIndex].re">
    <option value="" re=""></option>
    <option value="1" re="A1">A</option>
    <option value="2" re="B1">B</option>
    <option value="3" re="C1">C</option>
    <option value="4" re="D1">D</option>
    <option value="5" re="E1">E</option>
    </select>
    <input name=reInput value="" readonly>