how to code multiple Submit buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nehashri
    New Member
    • Jan 2007
    • 49

    how to code multiple Submit buttons

    hi

    i am doing a ASP front end. here I have 3 submit (buttons)[namely-search list, search contacts and search both] in my page and one text box. well what i want is- when ever the user writes a name in text box and clicks on one of the submit that perticular ASP code should work.

    i want to know how do i query for the different buttons. like if search list is clicked then search should happen only through list table of my database and so on.....

    how to code differently for different submit buttons in the same ASP code page.

    thanks
    neha
  • merseyside
    New Member
    • Mar 2007
    • 48

    #2
    A submit btn will only be posted if it has been clicked on even when there are two within the same form. Here's a quick test script

    Code:
    <%
    ' script : testsub.asp
    response.write("myText1 = " & request("myText1") & "<br />")
    response.write("myText2 = " & request("myText2") & "<br />")
    
    if ( trim(request("sub1")) <> "" ) then
       response.write("submit btn 1 clicked<br />")
    elseif ( trim(request("sub2")) <> "" ) then
       response.write("submit btn 2 clicked<br />")
    elseif ( trim(request("sub3")) <> "" ) then
       response.write("submit btn 3 clicked<br />")
    else
       response.write("no submit btns<br />")
    end if
    
    %>
    <form action="testsub.asp" method="post" name="myForm1">
    <input type="text" name="myText1" value="" /><br />
    <input type="submit" name="sub1" value="Submit btn 1" /><br />
    <input type="submit" name="sub2" value="Submit btn 2" /><br />
    </form>
    
    <form action="testsub.asp" method="post" name="myForm2">
    <input type="text" name="myText2" value="" /><br />
    <input type="submit" name="sub3" value="Submit btn 3" /><br />
    </form>

    Comment

    • nehashri
      New Member
      • Jan 2007
      • 49

      #3
      thanks for the help
      this code works well like this.....but it dont work when i have to retrive data from my Ms Access database.
      i am sure that my SQL query is correct as when with single submit button it works fine and displays required data. but with 2 submits it shows all my data and not the selected data
      neha

      Comment

      • merseyside
        New Member
        • Mar 2007
        • 48

        #4
        Originally posted by nehashri
        thanks for the help
        this code works well like this.....but it dont work when i have to retrive data from my Ms Access database.
        i am sure that my SQL query is correct as when with single submit button it works fine and displays required data. but with 2 submits it shows all my data and not the selected data
        neha
        Have you solved this?

        Comment

        • nehashri
          New Member
          • Jan 2007
          • 49

          #5
          Originally posted by merseyside
          Have you solved this?
          hey merseyside....
          no i have not solved it........i need 3 diff text box n 3 diff submits in a table form......by clicking a submit it should retrive data of that perticular name (in text box )from the database.....i have tried using it but it works only for the first textbox and sumbit....

          now im trying to divert the 2 other submits to other page and excute....but i still have prob.....but yes thanks for been conserned if u can help plz ....
          neha

          Comment

          • merseyside
            New Member
            • Mar 2007
            • 48

            #6
            Originally posted by nehashri
            hey merseyside....
            no i have not solved it........i need 3 diff text box n 3 diff submits in a table form......by clicking a submit it should retrive data of that perticular name (in text box )from the database.....i have tried using it but it works only for the first textbox and sumbit....

            now im trying to divert the 2 other submits to other page and excute....but i still have prob.....but yes thanks for been conserned if u can help plz ....
            neha
            Can you post the code you're using?

            Comment

            • nehashri
              New Member
              • Jan 2007
              • 49

              #7
              ok now this is the code.....
              Code:
              <HTML>
              <BODY>
              
              <%
              Actionvar=Request.QueryString("actionvar")
              strURL = Request.ServerVariables("URL")
              strSearch = Request.QueryString("search")
              strseffect = Request.form("seffect")
              strtgroup = Request.form("tgroup")
              strmechanism = Request.form("mechanism")
                
              btnID = "?"
              
                if Request.Form("bsubmit") = "Submit 1" then
                  btnID = "1"
              	
              Set conn = server.createobject("adodb.connection")
              	DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
              	DSNtemp=dsntemp & "DBQ=" & server.mappath("Databases/nprcDrugsDB.mdb")
              	conn.Open DSNtemp
              	
              	If strSearch <> "" Then
              	strSQL = "SELECT * " _
              		& "FROM Drug_Name, Chemistry, Pharmacology WHERE Drug_Name.Drug_ID = Chemistry.Drug_ID AND Drug_Name.Drug_ID = Pharmacology.Drug_ID AND Drug_Name.Synonyms LIKE '%" & strSearch & "%' " _
              		& "ORDER BY D_Name;"
              
              	Set rstSearch = conn.execute(strSQL)
              	%>
              
              	<table border="2" FRAME=box RULES=ALL CELLPADDING=9 BORDERCOLOR=RED >
              	<p><font size = 5><b>Chemistry: -</b></font><tr>
              	<th>Name</th>
              	<th>IUPAC Name</th>
              	<th>Molecular Formula</th>
              	<th>Salts</th>
              	<th>Propert</th>
              	</tr>
              	<%
              	Do While Not rstSearch.EOF
              		%>
                             	<tr>
              		<td><%= rstSearch.Fields("D_Name").Value %></td> 'from tbl Drug_Name
              		<td><%= rstSearch.Fields("iupac").Value %></td> ' from tbl Chemistry
              		<td><%= rstSearch.Fields("Mol_Form").Value %></td> ' from tbl Chemistry
              		<td><%= rstSearch.Fields("Salts").Value %></td> ' from tbl Chemistry
              		<td><a href = "">Properties</a>
              		</tr>
              	<%
              
              		rstSearch.MoveNext
              	Loop
              	%>
              	
              	</table>
              	
              	<% 
              	
              	rstSearch.Close
              	conn.Close
              	Set conn = nothing
              	Set strSQL = nothing
              	End If
              
                elseif Request.Form("bsubmit") = "Submit 2" then
                  btnID = "2"
              'similar code for search here
                elseif Request.Form("bsubmit") = "Submit 3" then
                  btnID = "3"
              'similar code for search here
                end if
              %>
              <FORM action="multibuttons.asp" method="post">
              First name: <INPUT type="TEXT" name="search" value="<%= strSearch %>"><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>
              let me tell u what this code do.
              here i have one text n 3 buttons....in my database i have 2 tables...... all i want is ven a user writes a name on the text box and click on submit it should
              check in 1st table Drug_name field synonymsfor its match and then with the help of Drug_ID field(which is common in both tables and primary key for both)it should list out the information (like iupac, salts, molecular formula) from the 2nd table ie., chemistry...... the code for retrival of data is correct it works well with one submit button....but if put 3 buttons like above its doesnt show any results....i hv even tried givin different name to buttons and call seperatly.... also diff text boxes with different name (here only one submit ie., 1st one works n not others)..... what method should i follow???????

              Comment

              • merseyside
                New Member
                • Mar 2007
                • 48

                #8
                At line 7 your expecting the search from the query string

                Code:
                strSearch = Request.QueryString("search")
                not the form

                Code:
                strSearch = Request.Form("search")

                Comment

                • nehashri
                  New Member
                  • Jan 2007
                  • 49

                  #9
                  Originally posted by nehashri
                  ok now this is the code.....[code]<HTML>
                  <BODY>

                  <%
                  Actionvar=Reque st.QueryString( "actionvar" )
                  strURL = Request.ServerV ariables("URL")
                  strSearch = Request.QuerySt ring("search")
                  strseffect = Request.form("s effect")
                  strtgroup = Request.form("t group")
                  strmechanism = Request.form("m echanism")
                  sorry line 8, 9 and 10 are not correct.....i was tryin something ven these lines i left as it is and as per line 7 im calling Query String....what u mean is i should call form?????
                  is this method correct?????? i mean all i want here is to write same kind of code here...
                  elseif Request.Form("b submit") = "Submit 2" then
                  btnID = "2"
                  'similar code for search here
                  elseif Request.Form("b submit") = "Submit 3" then
                  btnID = "3"
                  'similar code for search here
                  end if
                  and do i have to close and open SQL connection each time i mean for each button????
                  neha

                  Comment

                  • merseyside
                    New Member
                    • Mar 2007
                    • 48

                    #10
                    Originally posted by nehashri
                    sorry line 8, 9 and 10 are not correct.....i was tryin something ven these lines i left as it is and as per line 7 im calling Query String....what u mean is i should call form?????
                    Yes at line 7 user
                    Code:
                    request.form("search")
                    is this method correct?????? i mean all i want here is to write same kind of code here...
                    Yep. Basically that's what you want.

                    and do i have to close and open SQL connection each time i mean for each button????
                    neha
                    No, just have one open and close SQL connection. Simplest is to put the open as one of the first things in your script and close as one of the last.

                    Comment

                    • nehashri
                      New Member
                      • Jan 2007
                      • 49

                      #11
                      Originally posted by merseyside
                      Yes at line 7 user
                      Code:
                      request.form("search")


                      Yep. Basically that's what you want.



                      No, just have one open and close SQL connection. Simplest is to put the open as one of the first things in your script and close as one of the last.
                      hey thanks a lot the code is working perfectly.....t hankyou again
                      take care
                      regards
                      neha

                      Comment

                      • nehashri
                        New Member
                        • Jan 2007
                        • 49

                        #12
                        well this is good if i have 1 text and 2 or 3 sumbitts. but if i have 3 textboxes and three submits then......this type of thing is not working......ca n you guide me how to go about.......
                        neha

                        Comment

                        • merseyside
                          New Member
                          • Mar 2007
                          • 48

                          #13
                          Originally posted by nehashri
                          well this is good if i have 1 text and 2 or 3 sumbitts. but if i have 3 textboxes and three submits then......this type of thing is not working......ca n you guide me how to go about.......
                          neha
                          You mean something like the code snippet in post #2 above?

                          Comment

                          Working...