471,091 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,091 software developers and data experts.

Form validation w/ multiple buttons

I'm validating a form that has two buttons ("Next" and "Back"). The call
to the script is currently in the form's onSubmit() handler. Upon
pressing either button, the script runs. This is understandable, since
either button press is considered a submit. Is there a way to test which
button was pressed to determine whether or not to run the script?

Thanks,
Aaron

P.S. I've already tried attaching the same script to the "Next" button's
onSubmit() handler, and when doing so, the script is apparently never run.
Jul 23 '05 #1
1 1301
"Aaron C" <ag********@comcast.net> wrote in message
news:Yo********************@comcast.com...
I'm validating a form that has two buttons ("Next" and "Back"). The call
to the script is currently in the form's onSubmit() handler. Upon
pressing either button, the script runs. This is understandable, since
either button press is considered a submit. Is there a way to test which
button was pressed to determine whether or not to run the script?

Thanks,
Aaron

P.S. I've already tried attaching the same script to the "Next" button's
onSubmit() handler, and when doing so, the script is apparently never run.


One way is to set a variable via each Submit button's onClick then test it.

<html>
<head>
<title>onsubmit.htm</title>
<script type="text/javascript">
var bool;
function submits() {
bool ? alert("Prev") : alert("Next");
}
</script>
</head>
<body>
<form action="" method="post" onsubmit="return submits()">
<input type="submit" name="Prev" value="<=" onclick="bool=true">
<input type="submit" name="Next" value="=>" onclick="bool=false">
<form>
</body>
</html>
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Tim Johnson | last post: by
7 posts views Thread by A.M | last post: by
3 posts views Thread by D. Shane Fowlkes | last post: by
4 posts views Thread by Joe Abou Jaoude | last post: by
5 posts views Thread by jinukosh | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.