Website Designers R Us - Home
Using multiple submit buttons on a single form

Wondering how to create an HTML form with more than a single submit button and check which of those buttons was pressed?

First, let's create a form with a single submit button called "Submit 1" (assuming that the script we're calling to handle the form submission or the ACTION attribute is "mulsub.asp").

 
<FORM action="mulsub.asp" method="post">
First name: <INPUT type="TEXT" name="FNAME"><BR>
<INPUT type="submit" name="bsubmit" value="Submit 1">
</FORM>
 

Now let's add two more submit buttons to the form and call them "Submit 2" and "Submit 3."

<FORM action="mulsub.asp" method="post">
First name: <INPUT type="TEXT" name="FNAME"><BR>
<INPUT type="submit" name="bsubmit" value="Submit 1">

<INPUT type="submit" name="bsubmit" value="Submit 2">
<INPUT type="submit" name="bsubmit" value="Submit 3">
</FORM>
 

Note how we kept the name of all three submit buttons the same -- "bsubmit." The only difference is the "value" attribute with unique values -- "Submit 2" and "Submit 3." When we create the script, these unique values will help us to figure out which of the submit buttons was pressed.

Following is a sample Active Server Pages script to check for the submit button. We're simply checking the value of the button(s) named "bsubmit" and performing the appropriate action within the script.

<HTML><BODY>
<%
  btnID = "?"

  if Request.Form("bsubmit") = "Submit 1" then
    btnID = "1"
  elseif Request.Form("bsubmit") = "Submit 2" then
    btnID = "2"
  elseif Request.Form("bsubmit") = "Submit 3" then
    btnID = "3"
  end if
%>
Submit button ID: <%=btnID%>
</BODY></HTML>
 

Finally let's combine the HTML form tags and the script commands into a single ASP script.

 
<HTML>
<BODY>

<%
  btnID = "?"

  if Request.Form("bsubmit") = "Submit 1" then
    btnID = "1"
  elseif Request.Form("bsubmit") = "Submit 2" then
    btnID = "2"
  elseif Request.Form("bsubmit") = "Submit 3" then
    btnID = "3"
  end if
%>
Submit button ID: <%=btnID%><BR>

<FORM action="mulsub.asp" method="post">
First name: <INPUT type="TEXT" name="FNAME"><BR>
<INPUT type="submit" name="bsubmit" value="Submit 1">
<INPUT type="submit" name="bsubmit" value="Submit 2">
<INPUT type="submit" name="bsubmit" value="Submit 3">
</FORM>

</BODY>
</HTML>
 
Return to Listing

Website Designer R Us is one the leading website design companies on the internet. Based out of Toronto, Canada the company has dsigned and developed more than a 1000 websites worldwide.
 Home          ::             About Us          ::             Support            ::             Services            ::             Link Partners          ::             Contact

Copyright © 2006-2007 Website Designers R Us, a DOT Specialist Company. All rights reserved.