1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP/MySql database into JavaScript Array

Discussion in 'C#' started by Hazzardusa, Aug 15, 2005.

  1. #1
    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]);
    }
    }
    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

     
    Hazzardusa, Aug 15, 2005 IP
  2. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #2
    If you are convinced the way to go with this is with client-side code, the only way would be to create a 2 dimensional array to store your cities. You'd have to grab ALL city data from the database and inject some Javascript using ASP.

    Alternatively, you could simply write some Javascript to reload the page with a different querystring each time the 'state' combo box changes - the page itself could then load the city data from the database and you could populate the cities combobox using HTML written by ASP.

    - Jamie
     
    JamieC, Oct 19, 2005 IP