weixin_33674976 2016-03-29 05:36 采纳率: 0%
浏览 33

Ajax和文本框更改事件

I am developing an entry form. In the form there are two textbox. In one textbox when I type a keyword a DIV is opened and customer list having customerid and customername is displayed.

<form name="form1" action=""> 
customerid : <input type=text id="cusid" />
customername: <input type="text" id="custnm" onkeyup="showHint(this.value);" />
</form>


<div id="txtHint" style="width:250; background-color:cyan; display:none; ">

</div>

The customer list is displayed using ajax. Now in the list I have hyperlink on the CustomerID.

I want to return the customerID from the list back to the cusid textbox when user clicks the link. Also when user hits the tab button controls should transfer to the customer list. the same trigger should fire when user hits enter button and selected customerid should get filled in CUSId textbox.

Below is the procedure for ajax.

function showHint(str) {

  var xhttp;
  if (str.length == 0) { 
    document.getElementById("txtHint").innerHTML = "";
    return;
  }
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("txtHint").style.display="inline";
      document.getElementById("txtHint").innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("post", "getemp.asp?q="+str+"", true);
  xhttp.send();   
}

this is the getemp.asp file

sernm=request("q")
response.Write "<table>"
ks.open "select customer,customerid from customer where customername like '"&sernm&"%'",conn
if not ks.eof then
while not ks.eof
    vid=ks(1):if isnull(vid) or trim(vid)="" then vid=0
    acname=ks(0)
    'response.Write empnm &"&nbsp;"& ad1 &"&nbsp;"& ad2 &"&nbsp;"& ad3 &"<br>"  
    response.Write "<tr>"
    %>
    <td><a href="" onclick="return CloseWind('12');" ><%=vid%></a></td>
    <%
    response.Write "<td>"&acname&"</td>"
    response.Write "</tr>"

    ks.movenext
wend
end if
ks.close
response.Write "<table>"

This is the javascript for getting customerID

<script language="javascript">
function CloseWind(VID)
{
    document.forms['form1'].elements[CUSID].value=VID;
    return false;
}   
</script>

How could i get the customerid in the main form.

This is the same when we try to do voucher entry in tally.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器