...

View Full Version : using vbscript recordset in javascript



Boxhead
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?

Monkey

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

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

<h1><%=title%></h1>
<script>
var num = <%=num%>;
var str = "<%=str%>";
</script>

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
next
%>
<script type="text/javascript">
<%=jsStr%>
</script>

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';
</script>

Boxhead
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!!

monkey



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum