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

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    5

    Dynamic Dropdown list


    Hi,
    Can any one give some idea about dynamic dropdown list..This is the same code i have used..But I didn't understand the functionality..

    Can anyone give guidence.about this code how it works

    Code:
    <%
    Dim myConnection 'Object
    Dim myRS 'Object
    Dim myConnectString 'String
    Dim mySQL 'String
    Dim StartAuthor 'String
    Dim Cnt 'Integer
    Dim ListBox1 'String
    'Database Connect String
    
    myConnectString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("author.mdb")
    'Make Javascript Function to handle ListBox 2%>
    <script language="javascript">
    function listboxchange(p_index)
    {
    <%
    'SQL Statement which groupes all authors together, to handle more than 1 book per authormySQL = "SELECT * FROM Library Order By Author asc"
    
    Set myConnection = CreateObject("ADODB.Connection") 
    myConnection.open myConnectString
    'Get Recordset using our SQL
    Set myRS = myConnection.Execute(mySQL) 
    %>
    switch (p_index)
    {
    <%
    'Loop Through all authors and books
    Do Until myRS.eof 
    StartAuthor = myRS("Author")
    Cnt = 0
    
    %>
    case "<%=StartAuthor%>" :
    <% 
    'Loop until we disover a new author. Whilst author the same, add all of his/her books into grouped selection
    do until myrs.eof or StartAuthor <> myRS("Author")
    %>
    document.myform.listbox2.options[<%=cnt%>]=new Option("<%=myRs("Book")%>","<%=myRs("Book")%>");
    <%
    Cnt = Cnt + 1
    myrs.movenext
    if myrs.eof then exit do
    Loop
    %>
    break;
    <%
    Loop
    myRS.close
    Set myRS = nothing 
    %>
    }
    return true;
    }
    </script>
    
    
    <%
    'Make ListBox1
    'SQL Statement which selects each database entry for an author just once
    'as we don't want the same name twice in our list box
    mySQL = "SELECT DISTINCT Author FROM Library Order By Author asc"
    
    Set myConnection = CreateObject("ADODB.Connection") 
    myConnection.open myConnectString
    Set myRS = myConnection.Execute(mySQL) 
    
    'Make Drop down box Author list  
    do until myrs.eof
    ListBox1 = ListBox1 & "<option value=""" & myRs("Author") & """>" & myRs("Author") & "</option>"
    myRs.movenext
    loop
    
    myRS.close
    Set myRS = nothing 
    myConnection.close
    Set myConnection = nothing 
    %>
    </head>
    <body>
    <form name="myform" action="" method="get">
    <select name="listbox1" id="listbox1" onchange="javascript: listboxchange(this.options[this.selectedIndex].value);">
    <option value="">Please Select</option>
    <%=ListBox1%>
    </select>
    
    <select name="listbox2">
    <option value="">Please Select</option>
    </select>
    </form>
    
    
    </body>
    </html>
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    291
    Is it working correctly?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    5
    @vomster

    It's working fine..

    i am getting out put..

    But i don't know how values are selecting..and the functionality..(I just copied this code from another website).
    don't know the exact usage of the fields used..

    Thanks..
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    291
    You basically want to know how to adapt it to your system?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    5
    No Vomster..

    I don't need that. I changed the field names acording to my database .It's working fine
    Up to here i don't have problem..

    My problem here is with undertsanding the code..(developing)
    .. logic behind this code...like they are using arrays and some functions.. and how the values are passing..

    if you understand the code... well.. can you explain me line by line..

IMN logo majestic logo threadwatch logo seochat tools logo