Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004
    Location
    Dundee, Scotland
    Posts
    45

    Question Unanswered: Using Multiple Submit buttons in a single form

    I want to incorporate mutliple submit buttons for a single form, all buttons submit the same form and data, but process the form differently depending on which button was clicked.

    Things is how does the calling ASP page that processes the form know which button was clicked? I'd image you use something like an IF button1 Then...ElseIf Button2 etc etc statement, but don't know the exact syntax.

    Thanks!
    Sunday Ironfoot

    SQL Server 2000 n00b

  2. #2
    Join Date
    Mar 2004
    Posts
    58
    <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>

  3. #3
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    My coding conventions sometimes look like this snippet:

    ' See what btn used, where opened from, or where referred from.
    If Request.Form("btnClose") <> "" Then ' Close btn.
    ' Close.
    Call ClosePg()
    Elseif Request.Form("btnSave") <> "" Then ' Save btn.
    ' Set var.
    Call SetVar("frompost")

    ' Save rec.
    Call SaveRec()

    ' Show pg.
    Call ShowPg()
    Elseif Request.Form("btnNew") <> "" Then ' New btn from this pg.
    ' Set var.
    Call SetVar("new")

    ' Show pg.
    Call ShowPg()
    Elseif Request.Form("btnDel") <> "" Then ' Del btn.
    ' Set var.
    Call SetVar("frompost")

    ' Del rec.
    Call DelRec()

    ' Set var.
    Call SetVar("new")

    ' Show pg.
    Call ShowPg()
    Elseif Request.Form("btnShowList") <> "" Then ' ShowList btn.
    ' Set var.
    Call SetVar("frompost")

    ' Show pg.
    Call ShowPg()
    Elseif Request.QueryString("CustID") <> "" Then ' CustID from Many pg.
    Session(mstrSessionPrefix & "Cust-FromPg") = "custmany.asp"

    ' Set var.
    Call SetVar("fromdb")

    ' Show pg.
    Call ShowPg()
    Elseif Request.QueryString("CustID") = "" Then ' Add btn from MainMenu pg.
    Session(mstrSessionPrefix & "Cust-FromPg") = "mainmenu.asp"

    ' Set var.
    Call SetVar("new")

    ' Show pg.
    Call ShowPg()
    Else ' Nothing.
    ' This should never be the case.
    End If
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •