简体   繁体   English

在jsp中自动完成文本框

[英]auto complete text boxes in jsp

Ok i have found a solution regarding my problem. 好的,我找到了有关我的问题的解决方案。 I have three text boxes in my jsp page, when i am entering any data on first text box then control is going to get.jsp to retrieve data from database and is filling 2nd text box. 我的jsp页面中有三个文本框,当我在第一个文本框中输入任何数据时,控件将通过get.jsp从数据库中检索数据并填充第二个文本框。 But I want that data will go from first and second text boxes at a time to get.jsp to auto fill 3rd text box , but i was trying but data was going individually from either 1st or 2nd text boxes. 但是我希望数据一次从第一个和第二个文本框进入get.jsp以自动填充第三个文本框,但是我正在尝试,但是数据分别从第一个或第二个文本框进入。

----auto.jsp---------- ---- auto.jsp ----------

<%@page import="java.sql.*"%>
<html>
<head>  
<script language="javascript" type="text/javascript">  
var xmlHttp  
var xmlHttp
function showState(str){ 
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
   }
   else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
    }
if (xmlHttp==null){
alert ("Browser does not support XMLHTTP Request")
return
} 
var url="get.jsp";//goes to get.jsp
url += "?count=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange(){   
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
document.getElementById("country").innerHTML=xmlHttp.responseText;  
}   
}   
</script>  
</head>  
 <body>  
 <input id="name" type="text" name="name" onkeyup="showState(this.value)">
<br>  
<div id='country'>  
</div>  
</body> 
</html>

--------get.jsp------------- -------- get.jsp -------------

<%@page language="java" import ="java.sql.*" %>  
 <%  
 String name=request.getParameter("count");  
 String buffer="<div>";  
 //Got value from database 


while(rs.next()){
buffer=buffer+rs.getString(2)+"<br>";  
}  
buffer=buffer+"</div>";  
response.getWriter().println(buffer);  
%>

Here by request.getParameter("count"); 在这里通过request.getParameter(“ count”); I am getting only one text box value, but how can i get multiple value from auto.jsp by entering data in first and second text boxes. 我仅获得一个文本框值,但是如何通过在第一个和第二个文本框中输入数据来从auto.jsp获取多个值。

Just call the showState() function on your onkeyup and in the javascript function append the textbox's value. 只需在onkeyup上调用showState()函数,然后在javascript函数中附加文本框的值即可。

var url="get.jsp";//goes to get.jsp
url += "?count=" +document.getElementById(<first textbox's id>).value;
url += "&secondVal="+document.getElementById(<second textbox's id>).value;

and you can get the value like you did 您可以像以前一样获得价值

String secondVal=request.getParameter("secondVal"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM