简体   繁体   English

提交后,在另一个HTML页面上显示表单字段值

[英]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.

相关问题 如何在一种形式(提交后)中将值(在文本字段中)显示为另一种形式(两者都在同一页面上) - how to display a value(in text field) from one form(after submitting it) to another form (both are on the same page) 提交后如何在同一页中显示html表单值? - How to display html form values in same page after submit? 提交后在另一个页面中显示多个复选框的值 - Display the value of multiple checkboxes in another page after submit 在AngularJS中提交表单后重定向到另一个页面 - Redirect to another page after form submit in AngularJS 表单提交后重定向到另一个页面 - Redirect to another page after form submit 导航到另一个HTML页面后,如何在下拉列表中显示所选值? - How to display the selected value in dropdown after navigating to another html page? 加载页面后无法提交html表单 - Cannot submit a form in html after loading the page 显示表单取决于其他表单中字段的值 - Display Form Depending on the value of a field in another form 将值提交到另一页iframe表单 - Submit value to another page iframe form 使用getElementById()提交后,如何在下一页上显示具有多种值类型的html表单? - How to display html form with multiple type of values on next page after submit using getElementById()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM