vbscript recordset to javascript array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dana

    vbscript recordset to javascript array

    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

    #2
    Re: vbscript recordset to javascript array

    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" <djp5254@yahoo. com> wrote in message
    news:2ba7fcb9.0 402241332.b2839 9d@posting.goog le.com...[color=blue]
    > 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[/color]
    vbscript[color=blue]
    > (ms sql server database). My first question is, can i just use one
    > sql statement to grab everthing in the table and group them[/color]
    together,[color=blue]
    > how? the next question is, how do I convert a vbscript recordset to[/color]
    a[color=blue]
    > 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).[/color]


    Comment

    • Martin Walke

      #3
      Re: vbscript recordset to javascript array

      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" <djp5254@yahoo. com> wrote in message
      news:2ba7fcb9.0 402241332.b2839 9d@posting.goog le.com...[color=blue]
      > 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).[/color]


      Comment

      • Bob [BVP]

        #4
        Re: vbscript recordset to javascript array

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

        "Dana" <djp5254@yahoo. com> wrote in message news:2ba7fcb9.0 402241332.b2839 9d@posting.goog le.com...[color=blue]
        > 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).[/color]


        Comment

        Working...