Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Form validation w/ multiple buttons

Reply
Thread Tools

Form validation w/ multiple buttons

 
 
Aaron C
Guest
Posts: n/a
 
      12-04-2004
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.
 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      12-04-2004
"Aaron C" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
submit form data in multiple buttons on a html form Matt Javascript 1 07-05-2004 10:12 PM
submit form data in multiple buttons on a form Matt ASP General 2 06-27-2004 11:43 AM
submit form data in multiple buttons on a html form Matt HTML 0 06-26-2004 08:04 PM
validation controls...useless when form has multiple buttons? D ASP .Net 2 10-16-2003 06:36 PM
Multiple forms and Multiple submit buttons and validation sandyde2 Javascript 2 10-02-2003 09:25 AM



Advertisments