Wondering how to create an HTML form with more than a single submit ****on and check which of those ****ons was pressed?
First, let's create a form with a single submit ****on called "Submit 1" (assuming that the script we're calling to handle the form submission or the ACTION attribute is "mulsub.asp").
Listing #1 : HTML code. Download onesub.htm (0.26 KB).
Now let's add two more submit ****ons to the form and call them "Submit 2" and "Submit 3."
Listing #2 : HTML code. Download mulsub.htm (0.27 KB).
Note how we kept the name of all three submit ****ons 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 ****ons was pressed.
Following is a sample Active Server Pages script to check for the submit ****on. We're simply checking the value of the ****on(s) named "bsubmit" and performing the appropriate action within the script.
<%
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 ****on ID: <%=btnID%>
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.
<%
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 ****on ID: <%=btnID%>
Listing #4 : ASP/VBScript code. Download mulsub.asp (0.38 KB).