News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Using multiple submit buttons on a single form

Started by charleychacko, October 13, 2006, 01:44:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

charleychacko

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>
Listing #1 : HTML code. Download onesub.htm (0.26 KB).

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>
Listing #2 : HTML code. Download mulsub.htm (0.27 KB).

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>
Listing #3 : ASP/VBScript code. Download mulsub0.asp (0.28 KB).

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>
Listing #4 : ASP/VBScript code. Download mulsub.asp (0.38 KB).