Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > HTML Forum & Tutorial


Using multiple submit ****ons on a single form


Reply
Views: 2107  
Thread Tools Rate Thread
  #1  
Old 08-09-2010, 11:29 AM
bholas bholas is offline
Award Winner
 
Join Date: Apr 2010
Posts: 4,977
Default Using multiple submit ****ons on a single form

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").

First name:



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."

First name:






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%>



First name:








Listing #4 : ASP/VBScript code. Download mulsub.asp (0.38 KB).

Reply With Quote
Reply

Tags
website tips

New topics in HTML Forum & Tutorial





Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
WikiNewForum)