[英]how to display a value(in text field) from one form(after submitting it) to another form (both are on the same page)
So, I have the form1 where i am giving values in two fields and submitting it , 所以,我有form1,我在两个字段中给出值并提交它 ,
<form action="new_cand.php" name="form1" method="post">
<input type="number" name="aadhar_r" id="aadhar_r" required/>
<input type="text" name="cand_r" id="cand_r" required/>
<input type="submit" name="submit" id="submit" onclick="setValues();" />
</form>
I want these values to automatically be written and visible in the two textinput and numberinput fields in form2. 我希望这些值能够自动写入并在form2的两个textinput和numberinput字段中可见。
<form action="in_cand.php" name="form2" method="post">
<input type="number" id="a_number" name="a_number" required>
<input type="text" id="cid" name="cid" required>
<input type="submit" name="submit" id="submit" />
</form>
how do i use javascript to automatically set values visible and ready to submit to the fields in form2 ??? 我如何使用JavaScript自动设置可见值并准备提交到Form2中的字段?
Note : i'm using two forms because they both have different actions after clicking submit and both the forms are on the same page. 注意 :我使用的是两个表单,因为单击提交后它们都具有不同的操作,并且两个表单都位于同一页面上。
Here is one small example using id
hashes, with this idea, I think you can start, object hash
will have pair list, 这是一个使用
id
哈希的小例子,有了这个想法,我想你可以开始了,对象hash
将具有对列表,
You can restrict specific form by mentioning id of it, in place of $('form :input').on()
: 您可以通过提及特定ID来限制特定格式,以代替
$('form :input').on()
:
var hash = { aadhar_r : 'a_number', cand_r : 'cid' } $('form :input').on('keyup',function(){ if(this.id in hash){ $('#'+hash[this.id]).val($(this).val()) } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action="new_cand.php" name="form1" method="post"> <input type="number" name="aadhar_r" id="aadhar_r" required/> <input type="text" name="cand_r" id="cand_r" required/> <input type="submit" name="submit" id="submit" onclick="setValues();" /> </form> <form action="in_cand.php" name="form2" method="post"> <input type="number" id="a_number" name="a_number" required> <input type="text" id="cid" name="cid" required> <input type="submit" name="submit" id="submit" /> </form>
If you use jQuery, you can serialize your first form and send it directly to the server. 如果使用jQuery,则可以序列化第一个表单并将其直接发送到服务器。 Then you get the value from the input field and set it to the other input field.
然后,您从输入字段中获取值并将其设置为另一个输入字段。
Form 1: 表格1:
<form id="form1">
<input type="number" name="aadhar_r" id="aadhar_r" required/>
<input type="text" name="cand_r" id="idOfInput1" required/>
<button id="submit" />
</form>
Script: 脚本:
$("#submit").click(function () {
$.post("new_cand.php", $("#form1").serializeArray(), function () { /* Nothing to do with new_cand.php data */});
$("#idOfInput2").val($("#idOfInput1").val());
});
Form 2: 表格2:
<form action="in_cand.php" name="form2" method="post">
<input type="number" id="a_number" name="a_number" required>
<input type="text" id="idOfInput2" name="cid" required>
<input type="submit" name="submit" id="submit" />
</form>
Attention : this is not tested, requires jQuery and is for a post method 注意 :这未经测试,需要jQuery,用于post方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.