vbscript recordset to javascript array

Discussion in 'ASP General' started by Dana, Feb 24, 2004.

  1. Dana

    Dana Guest

    I have a form with a couple of dropdown fields. the dropdown fields
    get the value from one table which is a reference table. The table
    consists of 3 columns - type, id, name. An example would look like
    this:

    type id name
    fruits AP apple
    fruits GRA grapes
    chocolate SNI snickers
    chocolate MM m&m's

    Currently, I have multiple sql statements to query the db for each
    dropdown (Select * from tablename where type='fruits') using vbscript
    (ms sql server database). My first question is, can i just use one
    sql statement to grab everthing in the table and group them together,
    how? the next question is, how do I convert a vbscript recordset to a
    javascript array? I need to have the values on the client side so i
    can do a dependent dropdown (i.e. if apple is selected in one
    dropdown, MM needs to get selected).
    Dana, Feb 24, 2004
    #1
    1. Advertising

  2. Dana

    Tim Williams Guest

    If you could sit down and write the required javascript then you
    should be able to do it from vbscript in ASP. Just loop through the
    fields and write out the js to form the array. If you're going to use
    client-side js to build the selects then you don't need to split the
    recordsets up - just use one and make sure you have the type as a
    field in the array.

    Tim.



    "Dana" <> wrote in message
    news:...
    > I have a form with a couple of dropdown fields. the dropdown fields
    > get the value from one table which is a reference table. The table
    > consists of 3 columns - type, id, name. An example would look like
    > this:
    >
    > type id name
    > fruits AP apple
    > fruits GRA grapes
    > chocolate SNI snickers
    > chocolate MM m&m's
    >
    > Currently, I have multiple sql statements to query the db for each
    > dropdown (Select * from tablename where type='fruits') using

    vbscript
    > (ms sql server database). My first question is, can i just use one
    > sql statement to grab everthing in the table and group them

    together,
    > how? the next question is, how do I convert a vbscript recordset to

    a
    > javascript array? I need to have the values on the client side so i
    > can do a dependent dropdown (i.e. if apple is selected in one
    > dropdown, MM needs to get selected).
    Tim Williams, Feb 25, 2004
    #2
    1. Advertising

  3. Dana

    Martin Walke Guest

    Dana,

    You can use the getrows method which will retrieve all the rows into a vb
    array and then assign the vbarray values to the js array by using ubound for
    each dimension of the array and assign the values to the js array using
    response.write statements.
    Much quicker than reading each row of data and then manipulating it.

    In terms of your current solution, you should use 'select <fieldname> from
    ....' rather than 'select * from ...' as that's also quicker.

    Martin

    "Dana" <> wrote in message
    news:...
    > I have a form with a couple of dropdown fields. the dropdown fields
    > get the value from one table which is a reference table. The table
    > consists of 3 columns - type, id, name. An example would look like
    > this:
    >
    > type id name
    > fruits AP apple
    > fruits GRA grapes
    > chocolate SNI snickers
    > chocolate MM m&m's
    >
    > Currently, I have multiple sql statements to query the db for each
    > dropdown (Select * from tablename where type='fruits') using vbscript
    > (ms sql server database). My first question is, can i just use one
    > sql statement to grab everthing in the table and group them together,
    > how? the next question is, how do I convert a vbscript recordset to a
    > javascript array? I need to have the values on the client side so i
    > can do a dependent dropdown (i.e. if apple is selected in one
    > dropdown, MM needs to get selected).
    Martin Walke, Feb 25, 2004
    #3
  4. Dana

    Bob [BVP] Guest

    You could use a vbscript dicitonary object to do it, depend
    on size etc..

    "Dana" <> wrote in message news:...
    > I have a form with a couple of dropdown fields. the dropdown fields
    > get the value from one table which is a reference table. The table
    > consists of 3 columns - type, id, name. An example would look like
    > this:
    >
    > type id name
    > fruits AP apple
    > fruits GRA grapes
    > chocolate SNI snickers
    > chocolate MM m&m's
    >
    > Currently, I have multiple sql statements to query the db for each
    > dropdown (Select * from tablename where type='fruits') using vbscript
    > (ms sql server database). My first question is, can i just use one
    > sql statement to grab everthing in the table and group them together,
    > how? the next question is, how do I convert a vbscript recordset to a
    > javascript array? I need to have the values on the client side so i
    > can do a dependent dropdown (i.e. if apple is selected in one
    > dropdown, MM needs to get selected).
    Bob [BVP], Feb 26, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hung Huynh
    Replies:
    8
    Views:
    291
    Bob Barrows
    Sep 24, 2003
  2. Rob Meade

    array/recordset?

    Rob Meade, Feb 8, 2004, in forum: ASP General
    Replies:
    23
    Views:
    343
    Rob Meade
    Feb 8, 2004
  3. Tim Pollard
    Replies:
    8
    Views:
    144
    Ray Costanzo [MVP]
    Dec 3, 2004
  4. mad
    Replies:
    0
    Views:
    216
  5. Dana
    Replies:
    2
    Views:
    182
    Martin Walke
    Feb 25, 2004
Loading...

Share This Page