[thelist] JS: test which submit button was clicked.

Tab Alleman Tab.Alleman at MetroGuide.com
Fri Jun 4 10:32:30 CDT 2004


Tom Dell'Aringa wrote:

> The value of your submit button is equal to the VALUE attribute you
> set, which must not be set.
> 
> You could check which NAME - except you named them the same. You
> could give them unique IDs. A little more info on what you are trying
> to accomplish would help...

Ok, for the sake of further illustration...

<form name="FormName" onSubmit="TestRejection('FormName');"
action="SomeScript.asp" method="post">
<input type="submit" name="WhatToDo" value="Approve">
<input type="submit" name="WhatToDo" value="Reject">
</form>

Now, when this form is submitted, I can test Request.Form("WhatToDo") in
SomeScript.asp and find out which submit button the user clicked (that's
the "why").

What I want to do is write a JavaScript function (TestRejection) on the
page that contains the form that does something depending on which
submit button the user clicks.

I tried this:

function TestRejection(f)
	{
	alert(document.forms[f].WhatToDo.value);
	if (document.forms[f].WhatToDo.value == 'Reject')
		{
		return confirm('Are you sure you want to reject this
item?');
		}
	else
		{
		return true;
		}
	}


But, as I said, the alert says "undefined".  I want to know how my
JavaScript function can test to see which submit button the user
clicked.


More information about the thelist mailing list