Hazzardusa
Aug 15th 2005, 1:19 pm
what i am trying to do is create a Dynamically linked pair of ComboBoxes. State/City to be exact. you click on the state ComboBoxand select say california and you get say San Diego in the City ComboBox. i have everything worked out except how to set up my asp database connection to work with this javascript code.
function populatecombo(elem, index, array){
if (array.length >= index){
if (array[index]){
for (var i = 0; i < array[index].length; i= i + 2){
elem.options[elem.options.length] = new Option(array[index][i + 1], array[index][i]);
}
}
else{
elem.options[elem.options.length] = new Option("[none available]", 0);
}
}
else{
elem.options[elem.options.length] = new Option("[none available]", 0);
}
}
i already have a function that clears the combo box of its selections and my database is set up so that it has one table with the ID, StateID, StateName and CityName.
the sql statement selects all info from the table and fills the state ComboBox using seperate asp code. then i have the state ComboBox onChange event handler call the script to clear the city box, then repopulate the city box using the "populatecombo" script. nothing happens so far because i dont know how to transfer information from either a recordset table or an array in asp into javascript. the only thing i have been able to come up with would be to use an asp loop to write the javascript. i am trying to avoid this since i know very little javascript.
any help would be appreciated
function populatecombo(elem, index, array){
if (array.length >= index){
if (array[index]){
for (var i = 0; i < array[index].length; i= i + 2){
elem.options[elem.options.length] = new Option(array[index][i + 1], array[index][i]);
}
}
else{
elem.options[elem.options.length] = new Option("[none available]", 0);
}
}
else{
elem.options[elem.options.length] = new Option("[none available]", 0);
}
}
i already have a function that clears the combo box of its selections and my database is set up so that it has one table with the ID, StateID, StateName and CityName.
the sql statement selects all info from the table and fills the state ComboBox using seperate asp code. then i have the state ComboBox onChange event handler call the script to clear the city box, then repopulate the city box using the "populatecombo" script. nothing happens so far because i dont know how to transfer information from either a recordset table or an array in asp into javascript. the only thing i have been able to come up with would be to use an asp loop to write the javascript. i am trying to avoid this since i know very little javascript.
any help would be appreciated