Click to See Complete Forum and Search --> : one form, multiple submit buttons
neumy
07-25-2003, 12:47 PM
I'm creating a webpage with one form and multiple submit buttons. Each submit button will call a different action but access the same form.
As far as I am aware, each submit button calls the form action. There should be a way to change the action based on which submit button was pressed, but I can't seem to wrap my head around this problem.
If anyone can help me out, it would be appreciated.
Thanks.
Charles
07-25-2003, 12:51 PM
The problem is going to be keeping the form working for the 13% of users who do not have JavaScript. You'll need a serverside script that re-routs the forms for those folks. Use that script as the form's action and then with each button do something like:
<button type="submit" name="foo" onclick="this.form.action = 'foo.pl'">Submit to Foo</button>
Khalid Ali
07-25-2003, 12:51 PM
document.formName.action="whatever"
use the above line in all of the buttons onclick event call..
neumy
07-25-2003, 01:08 PM
believe-it-or-not, it's not working yet. Your code was appreciated, it's amazing what your forget when you need it. But for some reason, I can't seem to get it working.
Here's a sample code...
<form method="POST" name="check">
<table cellspacing=0 cellpadding=0 border=0>
<tr>
<td valign="top"><input type="checkbox" name="a[a0]" value="on" <? if($a[0]=="on") echo " CHECKED";?>></td>
<td>ONE</td>
</tr>
<tr>
<td valign="top"><input type="checkbox" name="a[a1]" value="on" <? if($a[1]=="on") echo " CHECKED";?>></td>
<td>TWO</td>
</tr>
</table>
<a href="" onClick="document.check.action='two.php'"><img src="next.gif" border=0></a>
<br><br><br>
<a href="" OnClick="document.check.action='three.php'"><img src="next.gif" border=0></a>
<br><br><br>
<button type="submit" name="one" onclick="this.check.action = 'two.php'"><img src="next.gif" border=0></button>
</form>
Now it gets the right info from the next page. I tried two different submit buttons, but the page just reloads.
Is something missing???
neumy
07-25-2003, 01:21 PM
Never mind. I figured it out. :D
<a onClick="document.check.action='two.php'; document.check.submit();"><img src="next.gif" border=0></a>
This is what ended working for me.
Thanks both for your input. It helped me out.