Jump to content

[SOLVED] Determining which submit was pressed


jordanwb

Recommended Posts

In my ASP form I have two submit buttons and I want to do validation. If button1 is pressed do this validation whereas if button2 two is pressed do this validation. I call the check in the form's onsubmit method.

 

I saw this: http://forums.aspfree.com/html-javascript-and-css-help-7/detect-which-button-was-pressed-in-javascript-40818.html but it doesn't work.

Link to comment
Share on other sites

I found out how. For others who are having the same problem:

 

In the <head> tag:

    <script type="text/javascript" language="javascript">
    <!--
        var button_pressed;
        function check_form (the_form)
        {
            if (button_pressed == the_form.add_addr)
            {
                alert ("Foo!");
            }
            else if (button_pressed == the_form.send_email)
            {
                alert ("It too is Foo!");
            }
            return false;
        }
    -->
    </script>

 

in my form:

 

<input id="add_addr" onclick="button_pressed=this;" runat="server" type="submit" value="Add Address" />

<input id="send_email" onclick="button_pressed=this;" runat="server" type="submit" value="Mass Send" />

 

Note: If you're not using ASP take out the runat="server"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.