vbscript recordset to javascript array

D

Dana

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

Tim Williams

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

Martin Walke

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top