View Full Version : using vbscript recordset in javascript

01-11-2004, 07:27 PM
I have an asp page using vbscript and dreamweaver's pop up menu javascript.

I want to populate the menu with information taken from a database using my vbscript.

How can I convert the information into javascript variables?


01-11-2004, 07:30 PM
The VBScript is server side and the JavaScript is client side, so they will not communicate directly. Use the VBScript to write the JavaScript source code to the document on the server, that the client will be able to parse.

01-12-2004, 09:12 AM
The same way you insert asp codes in html:

var num = <%=num%>;
var str = "<%=str%>";

If you like to populate a js array, you can make your vbscript string outputs js statements.

dim jsStr, vbArr
jsStr = "var arr=new Array();" & VbCrLf
for i = 0 to ubound(vbArr)
jsStr = jsStr & "arr[" & i & "]" = '" & vbArr(i) & "';" & VbCrLf
<script type="text/javascript">

Of course, if the array contains numbers not string, the single quote is not needed

Sample output would be:
<script type="text/javascript">
var arr=new Array();
arr[0] = 'blah';
arr[1] = 'blahblah';
arr[2] = 'blah';

01-12-2004, 10:13 AM
Thank you both, never thought of doing either of these things and have come across this problem loads - how simple the solution for a simple user!!