简体   繁体   中英

I have 1 form with 2 submit buttons

I am trying to set-up a form that has 2 buttons, accept and deny. It doesn't seem to be working. Any thoughts on what I should fix?

   <form name="iform" method="post" onsubmit="" onreset="" enctype="multipart/form-data"    action="formapprovedeny" class="iform">

Form content here.

   <input type="button" onclick="submitForm('html_form_approve.php')"      class="submit_button" value="Approved" name="Approved" />
   <input type="button" class="submit_button" onclick="submitForm('html_form_deny.php')" value="Denied" name="Denied" />


   </form>

Here is the script part.

     <script>
function submitForm(action)
{
    document.getElementById('formapprovedeny').action = action;
    document.getElementById('formapprovedeny').submit();
}
  </script>

Your Javscript is trying to submit a form with an id of formapprovedeny but your form does not have an id . Try adding id="formapprovedeny" to your form

You have a problem with your naming.

You try to get the form by it's id , but it is not set. It's name is.

You should use either getElementByName or give your form an id .

它应该id="formapprovedeny"而不是action="formapprovedeny"

<form name="iform" method="post" onsubmit="" onreset="" enctype="multipart/form-data"    id="formapprovedeny" class="iform">

The type of button must be 'submit' and the value whatever you want, look this:

<input type="submit" class="submit_button" value="Approved" name="Approved" />
<input type="submit" class="submit_button" value="Denied" name="Denied" />

What do you want to achieve using the 2 buttons? What do you expect? http://jsfiddle.net/xaW5P/

<script>
function submitForm(action)
{
    alert('hello submitForm '+action);
    document.getElementById('formapprovedeny').action = action;
    document.getElementById('formapprovedeny').submit();
}
  </script>

if I use your code (added an alert) this seems to work...whatever it should be doing ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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