Reputation: 65
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>
Upvotes: 0
Views: 113
Reputation: 156898
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
.
Upvotes: 0
Reputation: 1917
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
Upvotes: 3
Reputation: 3662
It should id="formapprovedeny"
not action="formapprovedeny"
<form name="iform" method="post" onsubmit="" onreset="" enctype="multipart/form-data" id="formapprovedeny" class="iform">
Upvotes: 0
Reputation: 657
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 ;)
Upvotes: -1
Reputation: 509
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" />
Upvotes: -1