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>