#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4

    Problem with multiple drop down boxes to retrieve data from database.


    Hi..

    My application has two drop down boxes..
    Once we select the option it should display the data from database.


    here is my program code..


    Code:
    <form method="post" action="test4.asp">
    <div align="center">
     
    <table align="Center">
    <tr><td>Menu Type</td>&nbsp;
    <%
    OpenSQLConn
    SQL = "Select * from menu order by m_id"
    Set rs = Conn.Execute(SQL)%>
    <td> <select name="optm">
         <option value="">Please Choose</option>
            <% Do While Not rs.EOF %>
        <option value="<%=rs("mid")%>"><%=rs("mid")%><%=rs("mtype")%>
        </option>
        <%
        rs.MoveNext
        Loop
        %>
    </select></td></tr>
    <tr><td> Size</td>
    <%
    SQL = "Select * from size order by sid"
    Set rs = Conn.Execute(SQL)%>
     <td> <select name="opts">
            <option value="">Please Choose</option>
            <% Do While Not rs.EOF %>
           <option value="<%=rs("sid")%>"><%=rs("sid")%><%=rs("size")%>
          </option>
          <%
          rs.MoveNext
         Loop
          %>
       </select></td></tr>
     
     
    </table>
    <input type="submit" value="Show Items " name="ssubmit" />
    
    <%
        OpenSQLConn
        if optm <> "" then 
            if opts <> "" then 
        Sql1="Select * from master where mid='" & optm & "' and sid='" &opts&"'"
          Set rs=Conn.Execute(sql1)
    %>
    <table width="60%" cellspacing="0" cellpadding="2" border="1">
    <%
            do until rs.EOF
         response.write("<tr>")
         response.write("<td>" & rs("mid") & "</td>")
         response.write("<td>" & rs("sid") & "</td>")
         response.write("<td>" & rs("mtype") & "</td>")
         response.write("<td>" & rs("size") & "</td>")
         response.write("<td>" & rs("measure") & "</td>")
        
         response.write("</tr>")
         rs.MoveNext
            loop
            rs.close
            Conn.Close
     
    %>
    </table>
     
    <%    
    end if
    end if
     %>
    </form>
    I am uanble to find out the error.. I thought the error must be with if condition or sqk statment..

    Can any one help me on this>?
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    291
    Shouldn't this line
    Code:
    Sql1="Select * from master where mid='" & optm & "' and sid='" opts&"'"
    be this?
    Code:
    Sql1="Select * from master where mid='" & request.form("optm")& "' and sid='" & request.form("opts") & "'"
    Last edited by Vomster; November 18th, 2010 at 01:52 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    No I am getting an error...


    error message:

    ADODB.Recordset (0x800A0CC1)
    Item cannot be found in the collection corresponding to the requested name or ordinal.
  6. #4
  7. No Profile Picture
    Stumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,409
    Rep Power
    4538
    The error is pretty self-explanatory and would even be clearer if you pointed out the exact line number in your code that is generating the error.

    You're referencing some rs("<columname>") in your asp code, and that column doesn't exist in the table
    ======
    Doug G
    ======
    It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    @ doug..

    There is a column with that name..

    and I have corrected it..
    still no use..

    error is
    Microsoft VBScript runtime (0x800A01A8)
    Object required: ''
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    @vomster and Doug

    Thanks

    I have corrected it..
    I have used
    optm=Request.form("optm")
    opts=Request.form("opts")

    then
    If statements


    .......
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    Can you help me here too..

    Based on my first drop down the items in the second drop down values sholud chage..
    For that what i have to mention..
    Do i need to use seprate databse table with thos fields..

    Thanks in advance..
  14. #8
  15. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    291
    I order to populate the second dropdown from the first you will need to use something like jQuery.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    isn't possible with vbscript? or JQuery is neccessary..

    I have no idea about jquery..did u ever used these kind of dropdowns.. if so can you help me here..
  18. #10
  19. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    291
    Just to clarify, you are wanting the second drop down to populate as you change the value of the first drop down with no post back?
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    @vomster

    yes..
  22. #12
  23. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    291
    I'd suggest jQuery for this.

    If you'd like to try I found this link that might be a good start.

    http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_26498993.html

    You'd find more by searching I'm sure.

    classic asp jquery dropdown

    Things like that.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    Thank you so much..That really helps me..

IMN logo majestic logo threadwatch logo seochat tools logo