[Javascript] Which submit caused the event?

Tedd Sperling tedd at sperling.com
Tue Jan 1 10:04:31 CST 2013


To all:

This list has been inactive for some time, so I thought I might submit a question to start the new year. So here it is:

Let's say I have a form containing three input statement, like so:

<form action="" method="post" name="myform"  onsubmit="javascript:test(); return false;" >
   < input type="submit" name="edit" value="Edit">
   < input type="submit" name="save" value="Save">
   < input type="submit" name="cancel" value="Cancel">
</form>

If this form is submitted, how can I tell what the user clicked via JavaScript?

I know how to gather the values from all the input statements via JS -- there's no problem with that. But the question is when the user clicks "Edit" for example, how can I tell via JS which submit input was clicked to trigger the form submission event? In other words, how to I determine what triggered the event? In this example, I need something that would tell me "Edit" was clicked.

Please do not confuse this post with how to gather data values, names, or other such form considerations -- the sole issue here is how to determine which input statement was used to trigger the form submission event.

Thank you,

tedd

_____________________
tedd at sperling.com
http://sperling.com



More information about the Javascript mailing list