简体   繁体   English

如何通过href将文本框值传递到另一个jsp页面

[英]How to pass a textbox value to another jsp page via href

I want to pass a data that has been entered in a text box 我想传递在文本框中输入的数据

Source page : page1.jsp Target page : page2.jsp 源页面:page1.jsp目标页面:page2.jsp

page1.jsp code page1.jsp代码

<input type="text" id="date" autocomplete="off" >
<br>
<button onclick='window.top.location.href ="page2.jsp?id=document.getElementByID('date').value">


onclick='window.top.location.href ="flush.jsp?id="document.getElementById('datepicker').value"'>

in what way can i pass the value entered in the text box through via href attribute ?? 我可以通过href属性以何种方式传递在文本框中输入的值?

You have to concatenate the string in javascript. 您必须在javascript中连接字符串。 I think you have mix up javascript code with JSP script ie page2.jsp?id=<%=date%> (this is JSP scripting) 我认为您已经将JavaScript代码与JSP脚本混在一起,即page2.jsp?id = <%= date%>(这是JSP脚本)

<button onclick='window.top.location.href="page2.jsp?id=" + document.getElementById("date").value;'>Submit</button>

Try using this-- 尝试使用-

<input type="text" id="date" autocomplete="off" value='ABC'/>
    <br>
        <button onclick='window.location ="page2.jsp?d="+document.getElementById("date").value'>Click me </button>

Heres the working Fiddle 这是工作的小提琴

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

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