[thelist] Multiple Submit Button per Form?
Joshua Olson
joshua at waetech.com
Thu Sep 26 09:39:01 CDT 2002
----- Original Message -----
From: "Jay Blanchard" <jay.blanchard at niicommunications.com>
Sent: Thursday, September 26, 2002 10:28 AM
> But the form action is the same. I guess I could all of the PHP code in a
> huge case statement and then choose the action as I have done before. I
was
> wanting the action choice to be made differently, but I know that cannot
be
> done. I wanted it done somehow in the form itself, which could be done
with
> JavaScript if need be.
Jay,
It can be done with JavaScript. You can change the action of the form tag
in the onclick of the submit button, Such as:
<input type="submit" onclick="this.form.action = 'newaction.asp?foo=bar';"
name="foo" value="bar">
Or, do something like this: [ warning: untested code ]
<script language="JavaScript" type="text/javascipt">
var globalVar;
function changeAction(form)
{
if (globalVar == 1) { form.action = ''newaction1.asp?foo=bar'; return
true; }
if (globalVar == 2) { form.action = ''newaction2.asp?foo=whatever';
return true; }
return false; // they submitted without clicking a button... cancel the
submit
}
</script>
<form method="post" action="action.asp" onsubmit="return
changeAction(this);">
<input type="submit" onclick="globalVar = 1" name="foo" value="bar">
<input type="submit" onclick="globalVar = 2" name="foo" value="bar2">
</form>
-joshua
More information about the thelist
mailing list