Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2003
    Location
    UK
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    using vbscript recordset in javascript

    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

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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>

  • #4
    Regular Coder
    Join Date
    Dec 2003
    Location
    UK
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •