【问题标题】:autocomplete in textbox inside same jsp page在同一jsp页面内的文本框中自动完成
【发布时间】:2012-02-06 18:57:32
【问题描述】:

我正在修改内容。 <div> 国家/地区内显示数据,但如何自动填充 auto.jsp 中的文本框?我从get.jsp 获取数据,get.jsp 的内容正在国家<div>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=" +document.getElementById("textbox1").value;
                url += "&secondVal="+document.getElementById("textbox2").value;
                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="textbox1" type="text" name="name" onkeyup="showState(this.value)"/> 
        <input id="textbox2" type="text" name="secondVal" onkeyup="showState(this.value)"/>
        <br>  
        <div id='country'>
            Here Iam getting data from get.jsp
        </div>  
        <input type="text"/> //how to fill up this text box based on previous textbox 1 and textbox 2(written just above)?
    </body> 
</html>

get.jsp

<%
    String s=request.getParameter("count");//Got first textbox value
    out.println(s);
    String secondVal=request.getParameter("secondVal");// Got second textbox value
    out.println(secondVal);
    request.setAttribute("s", s);
%>

<input type="text" value="<%=s%>"/>

【问题讨论】:

  • 请任何人提出答案
  • 你想把值返回到输入的名字还是第二个val,对吧?
  • ya..我想用我进入 div 国家/地区的值填充最后一个文本框(在 auto.jsp 中),我该怎么做?
  • @BalusC...谢谢任何帮助

标签: javascript jquery ajax jsp


【解决方案1】:

查看您的函数stateChange(),您正在更改country 的值。因此,您可以更改它以将结果也应用于其他元素,例如:

function stateChange(){   
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
    document.getElementById("country").innerHTML = xmlHttp.responseText;  
    document.getElementById("textbox2").value = xmlHttp.responseText;
  }   
}  

【讨论】:

  • 是的,我得到了值,但是如果有多个值,我应该如何在 get.jsp 中编辑?
  • 来自 ajax 或来自输入用户的多个值?这里的一些样本会有所帮助。并且为了避免太多的 cmets,你能更新你的问题吗?
猜你喜欢
  • 2019-11-27
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-27
  • 2013-07-18
  • 1970-01-01
相关资源
最近更新 更多