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.

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"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.