Click to See Complete Forum and Search --> : Is it possible to make an ASP-page sense which submit button was used to submit form?


Pelle
02-14-2005, 05:31 AM
I have a stateic web page with a form on. The form can be submitted in either of two ways.

1. By the Java Script function "document.form.submit()". This function is called everytime changes are made in the form.
2. When the user manually clicks the submit button present in form.

I want the ASP page to treat the form differently depending on which submit procedure was used.

Is it possible to achieve that?
If so how?
Could I for example assign an argument to each submit procedure which could be retrieved in the ASP page and thereby used to identify which procedure was used? If so, how?

buntine
02-14-2005, 07:45 AM
You could call a JavaScript function that sets the value of a hidden field on the page and then submits the form.

<script language="JavaScript">
function submitForm()
{
document.getElementByID('hdnButtonPressed').value = "false";
document.form.submit();
}
</script>
...
<input type="hidden" name="buttonPressed" id="hdnButtonPressed" value="true" />

Regards.

Kilroy_waz_here
02-15-2005, 03:41 PM
you could give your button a name (don't use submit - you'll hate yourself when you finally figure out where the Javascript error comes from - see below) Then you could test to see if the Request.Form("myButtonName") was in your request object. If it is the button was pushed, if not you might assume the javascript submit happened but I would have some hidden-field value to verify that - just my preference.

N.B.:
If you do name your button "submit", your form will have a button-object ellement named submit. The form cannot have a submit() method and any other object of the same name ... I once spent hours trying to figure out why this was happening in some code we had inherited. Only to have to go through it again a few months later because I didn't document it and tell all my associates about it the first time we ran into it.