PDA

View Full Version : Knowing which submit button was pushed


ventura
12-27-2002, 11:36 PM
is it possible to know which submit button was pushed and run a validation script based on that button only?

i have two buttons - one named "submit" and the other is "go back". they are both type=submit buttons. i want to run a validation script that runs ONLY when the "submit" button is pushed and not the "go back" button.

duniyadnd
12-27-2002, 11:53 PM
not quite sure what your code exactly does, but try changing one of the submits to a type="button" instead of type="submit".

This way you can run the script onSubmit function for the one that counts, and don't have to keep track.

Duniyadnd

ventura
12-28-2002, 12:05 AM
where would i put the onSubmit validation? does it go in the <form> tag or the actual buttons <input> tag?

whammy
12-28-2002, 01:28 AM
There should never be a question about which "submit" button was pushed, since you should only use one form on a page whenever possible.

If you're trying to validate form input then you should use:

<form onsubmit="return validate()">

assuming "validate()" is a function you created.

As demonstrated before, you can use a "button" that will NOT submit your form, like so:

<input type="button" onclick="alert('I need to take some forms tutorials!')" />

;)

P.S. No offense meant by that at all - check out http://www.webmonkey.com for some really great tutorials regarding javascript and forms!