www.webdeveloper.com
Results 1 to 3 of 3

Thread: Is it possible to make an ASP-page sense which submit button was used to submit form?

  1. #1
    Join Date
    Nov 2004
    Posts
    121

    Question Is it possible to make an ASP-page sense which submit button was used to submit form?

    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?

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    You could call a JavaScript function that sets the value of a hidden field on the page and then submits the form.
    Code:
    <script language="JavaScript">
       function submitForm()
       {
          document.getElementByID('hdnButtonPressed').value = "false";
          document.form.submit();
       }
    </script>
    ...
    <input type="hidden" name="buttonPressed" id="hdnButtonPressed" value="true" />
    Regards.

  3. #3
    Join Date
    Feb 2005
    Posts
    4
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles