[英]Display form field value on another html page, after submit
I really need help... :-) I have two html pages and forms on both of them. 我真的需要帮助... :-)我在两个页面上都有两个HTML页面和表单。 I need solution to show field value from first form (on first page) in field on second form, after click on SEND button.
在单击“发送”按钮后,我需要解决方案以在第二个表单的字段中显示第一个表单(第一页)的字段值。 But, I need both pages to stay open, on first I need to insert values and on second page that values should be shown.
但是,我需要两个页面都保持打开状态,首先我需要插入值,然后在第二页上应该显示值。 Also, I need a solution without PHP because this app will be running on local devices, without server.
另外,我需要没有PHP的解决方案,因为此应用程序将在没有服务器的本地设备上运行。 I don't have any solution and please, I need some tips how I can do that.
我没有任何解决方案,请给我一些提示,以帮助我做到这一点。
I found here some solutions with localStorage and it looks interested but I need to stay on First page and send field value to Second page, in live. 我在这里找到了与localStorage有关的一些解决方案,它看起来很有趣,但是我需要停留在第一页上并将字段值实时发送到第二页。 There is code which I found here, this is example what I need, just I need both pages to be open and after I insert some value in field on first page and click on button, that value should be shown in field on second page.
我在这里找到了代码,这是我需要的示例,只需要打开两个页面,然后在第一页的字段中插入一些值并单击按钮后,该值就会在第二页的字段中显示。 Thank you in advance!
先感谢您!
<html>
<head>
<title>First Page</title>
<script type="text/javascript">
function saveVal() {
var inputFirst = document.getElementById("name").value;
localStorage.setItem("name", inputFirst);
inputFirst = localStorage.getItem("name");
}
</script>
</head>
<body>
<form action="secondPage.html" method="get">
<label>
First Name:
<input name="name" size="20" maxlength="25" type="text" id="name" />
</label>
<input type="submit" value="submit" onclick="saveVal()"/>
</form>
</body>
</html>
<html>
<head>
<title>Second Page</title>
</head>
<body>
<form action="#">
<label>
First Name:
<input name="name" size="20" maxlength="25" type="text" id="name"
readonly="readonly" />
</label>
<script type="text/javascript">
var storedVal = document.getElementById("name");
storedVal.value = localStorage.getItem("name");
</script>
</form>
</body>
</html>
You can use setInterval to constantly check and set the value: 您可以使用setInterval不断检查和设置值:
//this will run storeCheck function every 250 miliseconds and update values from localStorage.
setInterval(storeCheck, 250);
function storeCheck() {
var storedVal = document.getElementById("name");
storedVal.value = localStorage.getItem("name");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.