www.webdeveloper.com
Results 1 to 10 of 10

Thread: Classic asp page to send value of combo box

  1. #1
    Join Date
    May 2012
    Posts
    6

    Classic asp page to send value of combo box

    I have a simple asp page that has a dropdown combo box that is populated from a query to a database when the page is loaded and a text box. The user makes a selection from the drop down box and enters some data in the text boxe. Once everything is ok - hits submit. I want the value of the combobox and data in the text boxes to be sent to another asp page with a form post:

    <form name="MyForm" method="post" action="Add.asp">

    The problem is the <form is outside the %> of the asp code and the data from the combobox is not making it to the other page (the text box data is making it). I assume this is the issue. Any ideas on how to get the value of a combo box to be sent by a form post?

  2. #2
    Join Date
    Mar 2006
    Location
    Discworld
    Posts
    75
    what exactly does this means:

    the <form is outside the &#37;> of the asp code

    Are you sending data to other domain? Html page?

  3. #3
    Join Date
    May 2012
    Posts
    6
    Thanks for replying. The 2 parts of the page are the asp part (inside the <% %>) and the plain html part. The asp part loads the combo box with values from a database. The html part has the <form name="MyForm" method="post" action="Add.asp"> code which takes values from some text boxes which are entered manually after the page loads.

    The problem is that when I try to send the value of the text boxes and the combo box to another asp page, the value of the combo box is nothing no matter what I select in the combo box. I tried putting the <form name="MyForm" method="post" action="Add.asp"> code in the asp portion but get an error so I assume the post action has to be outside the asp section. The code is at work or I would post it. I did some searches and the only samples I could find for sending data from one page to another are straight html pages and none sending values from combo boxes.

    So I guess the generic question is once a combo box is loaded - how do I send its value to another page via <form name="MyForm" method="post" action="Add.asp">?

    Thanks for any ideas

  4. #4
    Join Date
    Mar 2006
    Location
    Discworld
    Posts
    75
    Can you post your code. Most likely you have something wrong with request on your code.
    Can not say without code.
    for example you have combo box id=cmbState inside form.
    On the post you need to str_cmbState=request("cmbState")
    and then pass this value to what ever you trying to do with it.
    You can not do it on straight HTML pages unless you have JavaScript URL processing function. And from your form code I can see that you are submitting to add.asp page.
    Best way to help you is to see your code.

  5. #5
    Join Date
    May 2012
    Posts
    6
    Here is the code. It does everything except send the value of the drop down box.

    Code:
    <html><head><title></title><script type="text/vbscript"></script></head><body>
    <%
    Dim adoCon
    Dim rsDrill
    Dim strSQL
    
    Set adoCon = Server.CreateObject("ADODB.Connection")
    adoCon.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Drill.mdb")
    Set rsDrill = Server.CreateObject("ADODB.Recordset")
    
       strSQL = "SELECT distinct Table1.DrillInfo from Table1 order by table1.DrillInfo asc;"
       rsDrill.Open strSQL, adoCon
    
    response.write("<select name='TheSerial'>")
    do while not rsDrill.EOF
       response.write("<option value=" & rsDrill("DrillInfo") & ">" & rsDrill("DrillInfo") & "</option>")
       rsDrill.movenext
    loop
    response.write("</select>")
    
    rsDrill.close
    Set rsDrill = Nothing
    Set adoCon = Nothing
    %>
    
    <form name="MyForm" method="post" action="Drill_Add.asp">
    TextBox Text: &nbsp;&nbsp;&nbsp;<input type="text" name="thename" maxlength="13">
    <input type="submit" name="submit" value="Submit">
    
    </form>
    </script>
    </body></html>

  6. #6
    Join Date
    Mar 2006
    Location
    Discworld
    Posts
    75
    Here it is.
    Try.
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <&#37;
    session("orderid")=session.SessionID
    session.Timeout=20
    %>
    
    <title></title>
    </head><body>
    <%
    Dim adoCon
    Dim rsDrill
    Dim strSQL
    
    Set adoCon = Server.CreateObject("ADODB.Connection")
    adoCon.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Drill.mdb")
    Set rsDrill = Server.CreateObject("ADODB.Recordset")
    
       strSQL = "SELECT distinct Table1.DrillInfo from Table1 order by table1.DrillInfo asc;"
       rsDrill.Open strSQL, adoCon
    str_select="" 
    str_select=str_select & "<select name='TheSerial'>"
    do while not rsDrill.EOF
       str_select=str_select & "<option value=" & rsDrill("DrillInfo") & ">" & rsDrill("DrillInfo") & "</option>"
       rsDrill.movenext
    loop
    str_select=str_select & "</select>"
    
    rsDrill.close
    Set rsDrill = Nothing
    Set adoCon = Nothing
    %>
    
    <form name="MyForm" method="post" action="Drill_Add.asp">
    Drop Down: &nbsp;&nbsp;&nbsp;<%=str_select%>
    TextBox Text: &nbsp;&nbsp;&nbsp;<input type="text" name="thename" maxlength="13">
    <input type="submit" name="submit" value="Submit">
    
    </form>
    
    </body></html>

  7. #7
    Join Date
    May 2012
    Posts
    6

    Thumbs up

    That's awesome. There is an issue with some of the entries with spaces in the values, but it is good to figure out what I was initially doing wrong.

  8. #8
    Join Date
    May 2012
    Posts
    6

    Talking

    I put quotes in the code and everything works like I was hoping...Thanks

  9. #9
    Join Date
    Mar 2006
    Location
    Discworld
    Posts
    75
    You can user variable session("orderid") as your session verification and to make sure that same value not submitted more than once. Normally that is where database indexes comes handy but sometimes it is good idea not to overload database...
    Especially access database.
    Plus I do not see in your code closing connection. Since your database is Access make sure that you do close connection or your website will die by slow and painful death.

  10. #10
    Join Date
    May 2012
    Posts
    6

    Thumbs up

    Got it and got the close db as well. Thanks again for the helps and tips. I finished that project over the weekend and it does everything I wanted.

    Cheers

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles