简体   繁体   English

如何在一种形式(提交后)中将值(在文本字段中)显示为另一种形式(两者都在同一页面上)

[英]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的两个textinputnumberinput字段中可见。

<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.

相关问题 提交表单后如何清除之前的文本字段值而不刷新整个页面? - How do I clear the previous text field value after submitting the form with out refreshing the entire page? 提交表单后如何清除字段并在页面重新加载后显示表单值 - How to clear a field after submitting a form and display the form values after the page reloads 提交后,在另一个HTML页面上显示表单字段值 - Display form field value on another html page, after submit 提交表单后从另一个页面(如确认页面)重定向后,如何将值保留在表单中 - How to keep the values in a form after getting redirected from another page(like a confirmation page) after submitting the form 以 HTML 格式提交表单后,显示来自另一个页面的部门内的内容 - Display the content inside a division from another page after submitting a form in HTML 在javascript中提交表单后如何在输入框中显示日期字段? - How to display the date field in input box after submitting the form in javascript? 提交表单后如何显示隐藏的表单? - How to display a hidden form after submitting a form? 提交表单后,localStorage页面不显示 - localStorage page does not display after submitting form 如何将文本从一页移到另一页的形式 - How to move text from one page into the form of another page 提交表单后如何在同一页面中获取成功消息? - How to get the success message in the same page after submitting the form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM