简体   繁体   English

如何以自动提交的形式命名的JavaScript

[英]how to give name in auto submit form javascript

This is my code that I am using to submit form with post value 这是我用来提交具有邮政价值的表格的代码

 <form action="<?php echo DOMAIN; ?>contact/booking-form.php" method="post">
  <input type="text" name="name" value="<?php echo $name; ?>" />
    <input type="text" name="email" value="<?php echo $email; ?>" />
    <input type="submit" name="submit" id="submit"  />
    <script>document.getElementById('submit').submit();</script>  
  </form>

Can anybody help me to pass name="submit" value of submit button to another page? 有人可以帮我将提交按钮的name="submit"值传递给另一页吗?

     <form id=submit action="<?php echo DOMAIN; ?>contact/booking-form.php" name="form1" method="post">
  <input type="text" name="name" value="<?php echo $name; ?>" />
    <input type="text" name="email" value="<?php echo $email; ?>" />

  </form>
<script >
        document.form1.submit()

    </script>

there is no sumit button in your code. 您的代码中没有sumit按钮。 first add in html 首先添加html

<input type="submit" value="submit" id="submit"/>
<script>
  document.getElementById("submit").value = "newSubmitButtonValue";
</script>

A submit button is only going to be a successful control if it is used to submit the form (and even then only if it has a name and a value … which yours does not). 如果使用提交按钮来提交表单,那么提交按钮将是一个成功的控件(即使只有名称和值……您也没有)。

If you want submit=submit in your form data when you submit the form with JavaScript, then don't use a submit button to put that data in the form in the first place. 如果在使用JavaScript提交表单时要在表单数据中进行submit=submit ,则不要使用“提交”按钮将数据首先放在表单中。 Use a hidden input. 使用隐藏的输入。

<input type="submit">
<input type="hidden" name="submit" id="submit" value="submit">

Then you have two other problems. 然后,您还有另外两个问题。

First, submit is a method of form elements, not inputs. 首先,submit是一种表单元素而非输入的方法。 So you need to change your script to call the right element. 因此,您需要更改脚本以调用正确的元素。

<script>document.getElementById('submit').form.submit();</script>

Second, if a form has a control called submit then that will clobber the submit method. 其次,如果一个表单有一个叫做控制submit ,然后将痛殴的submit方法。 So you need to get one from a different form (not supported in old versions of Internet Explorer): 因此,您需要从其他表格中获取一个(旧版本的Internet Explorer不支持):

<script>
var form = document.getElementById('submit').form;
var submit_method = document.createElement("form").submit;
submit_method.call(form);
</script>

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

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