View Full Version : how to fix my dynamic pulldown?

Dec 20th, 2006, 04:48 PM
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..

<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]);

<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")
set rs=nothing
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")
if not rs("City") = strCity then
response.write("<script>addCity('" & rs("State") & "','" & rs("City") & "')</script>")
strCity = rs("City")
end if
end if
set rs=nothing

<form name="frmAddress" method="POST" action="">
<td>STATE ID:</td>
<td><input type=text hidden="true" name="text1" /></td>
<td>CITY ID</td>
<td><input type=text hidden="true" name="text2" /></td>
<select size="1" name="State" onChange="loadCityList();">
[<select size="1" name="City">
<input type="submit" value="Submit" name="save" />
<input type="reset" value="Reset" name="clear" />

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..


Dec 20th, 2006, 11:49 PM
kindly help me resolve my code..