Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to fix my dynamic pulldown?


    hey frends..
    i had to create a asp page with 2 select pulldowns(state,city),options to b displayed in the CITY depends on STATE choice.

    the option list is to retrived from a db dynamically.

    i have a table with fields--state,stateID,city,cityID.

    here is the code snippet i have..

    Code:
    <html>
    <head>
    <title>testpage</title>
    <script language=javascript >
    var States = new Array();
    var Cities = new Array();
    
    function addState(state) {
       
        v = States.length;
       States.length ++;
       States[v] = state;
       v = Cities.length;
       Cities.length ++;
       Cities[state] = new Array();
    }
    
    function addCity(state,city) {
          v = Cities[state].length;
      
        Cities[state].length ++;
      
        Cities[state][v] = city;
    }
    
    function loadStateList() {
       
        var ctrlState = document.frmAddress.State;
        ctrlState.options.length = 0;
        for (i=0;i<States.length;i++) {
        ctrlState.options[i] = new Option(States[i],States[i]);
        }
    }
    
    function loadCityList() {
      
        var ctrlState = document.frmAddress.State;
        var selState = ctrlState.options[ctrlState.selectedIndex].value;
       
        var ctrlCity = document.frmAddress.City;
        ctrlCity.options.length = 0;
      
        for (i=0;i<Cities[selState].length;i++) {
            ctrlCity.options[i] = new Option(Cities[selState][i]);
        }
    }
    </script>
    
    </head>
    <body onload="loadStateList();loadCityList();">
    
    <%
    ' Open Database and setup a recordset with States Listed.
    set conn = server.createobject("ADODB.Connection")
    Conn.open("driver={SQL Server};server=xxxxxxx;uid=xxxxxxx;pwd=xxxxxxx;database=xxxxxxx;network=dbmssocn")
    strSQL = "Select State, city from tbAddress Order by State,city"
    set rs = conn.execute(strSQL)
    
    
    if rs.eof then
        response.write("No Addresses Found")
        rs.close
        set rs=nothing
        response.end
    end if
    
    strState = ""
    strCity = ""
    do until rs.eof
        if not rs("State") = strState then
            response.write("<script>addState('" & rs("State") & "')</script>")
            response.write("<script>addCity('" & rs("State") & "','" & rs("City") & "')</script>")
            strState = rs("State")
            strCity = rs("City")
        else
            if not rs("City") = strCity then
                response.write("<script>addCity('" & rs("State") & "','" & rs("City") & "')</script>")
                strCity = rs("City")
            end if
        end if
        rs.MoveNext
    loop
    rs.close
    set rs=nothing
    %>
    
    
    <form name="frmAddress" method="POST" action="">
        <table>
            <tr>
                <td>STATE ID:</td>
                <td><input type=text hidden="true" name="text1" /></td>
            </tr>
            <tr>
                <td>CITY ID</td>
                <td><input type=text hidden="true" name="text2" /></td>
            </tr>
            <tr>
                <td>State</td>
                <td>
                    <select size="1" name="State" onChange="loadCityList();">
                    </select>
                </td>
            </tr>
            <tr>
                <td>City</td>
                <td>
                    [<select size="1" name="City">
                    </select>
                </td>
            </tr>
            </table>
        <p>
        <input type="submit" value="Submit" name="save" />
        <input type="reset" value="Reset" name="clear" />
        </p>
    </form>
    </body>
    </html>
    NOW..how can i modify the code,so that wen the option is selected in the STATE & CITY lists,simulteneously the stateID,cityID are filled in 2 hidden textboxes,Text1 & Text2..

    kindly help..
    thanks..

    regards,
    kanith
    [
    Last edited by kaniths; 12-21-2006 at 02:04 PM.

  • #2
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    kindly help me resolve my code..
    Last edited by kaniths; 12-21-2006 at 02:01 PM.


  •  

    Posting Permissions

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