ASP
  Home arrow ASP arrow Converting VBScript Array to Javascript Ar...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Converting VBScript Array to Javascript Array in the same ASP Page (1D and 2D) by Anand Venkatraman
By: AnandV
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 21
    2003-01-01

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Converting VBScript Array to Javascript Array in the same ASP Page (1D and 2D) by Anand Venkatraman We come across lot of times a need to convert an Array from ASP page to Javscript, so that we can manipulate in the HTML form using Javascript. Here is an example of how to do that. I have two include files, one for 1D array, one for 2D ar ...

     

    We come across lot of times a need to convert an Array from ASP page to Javscript, so that we can manipulate in the HTML form using Javascript. Here is an example of how to do that. I have two include files, one for 1D array, one for 2D array and one example page calling those files. You can modify the array, ie calling from a Database (result set) or a COM Component (VB Array) and have the array in Javascript and populate HTML forms and manipulate. Some documentation is available in the code itself. Happy programming!!!

    Any questions regarding these files, please feel free to contact anand_venkatraman@yahoo.com

     

    This is the calling page code

    <!-- #INCLUDE FILE = "VB2JSarray2D.inc" -->
    <!-- #INCLUDE FILE = "VB2JSarray1D.inc" -->
    <HTML>
    <HEAD>
    <!--What ever U wanna write -->
    </HEAD>
    <BODY>
    <!--What ever U wanna write -->
    <%
    Dim arrUserInfo1D(4)

    arrUserInfo1D(0) = "Name1"
    arrUserInfo1D(1) = "Name2"
    arrUserInfo1D(2) = "Name3"
    arrUserInfo1D(3) = "Name4"
    arrUserInfo1D(4) = "Name5"

    Call ConvertToJSArray1D(arrUserInfo1D,"arrUserInfo1D")
    Response.Write("<H2>One Dimensional Array</H2>")
    %>

    <SCRIPT LANGUAGE="JAVASCRIPT">

    document.write("<table border=1>");
    for (i=0; i < arrUserInfo1D.length; i++)
    {
        document.write("<tr>");
    document.write("<td>");
        document.write(arrUserInfo1D[i]);
        document.write("</td>");
        document.write("</tr>");
    }
    document.write("</table>");

    </SCRIPT>

    <%

    Dim arrUserInfo2D(2,4)

    arrUserInfo2D(0,0) = "FirstName1"
    arrUserInfo2D(0,1) = "FirstName2"
    arrUserInfo2D(0,2) = "FirstName3"
    arrUserInfo2D(0,3) = "FirstName4"
    arrUserInfo2D(0,4) = "FirstName5"

    arrUserInfo2D(1,0) = "LastName1"
    arrUserInfo2D(1,1) = "LastName2"
    arrUserInfo2D(1,2) = "LastName3"
    arrUserInfo2D(1,3) = "LastName4"
    arrUserInfo2D(1,4) = "LastName5"

    arrUserInfo2D(2,0) = "Age1"
    arrUserInfo2D(2,1) = "Age2"
    arrUserInfo2D(2,2) = "Age3"
    arrUserInfo2D(2,3) = "Age4"
    arrUserInfo2D(2,4) = "Age5"

    Call ConvertToJSArray2D(arrUserInfo2D,"arrUserInfo2D")
    Response.Write("<H2>Two Dimensional Array</H2>")

    %>

    <SCRIPT LANGUAGE="JAVASCRIPT">

    document.write("<TABLE BORDER='1'>");
    for (i=0; i < arrUserInfo2D.length; i++)
    {
        document.write("<TR>");
        for (j=0; j < arrUserInfo2D[i].length; j++)
        {
        document.write("<TD>");
            document.write(arrUserInfo2D[i][j]);
            document.write("</TD>");
        }
            document.write("</TR>");
    }
    document.write("</TABLE>");

    </SCRIPT>
    <!--What ever U wanna write -->
    </BODY>
    </HTML>

    1st Include File

    <%
    '**************************************************
    'Name        : VB2JSarray1D.inc
    'Description    : Include File used to convert a VBScript One Dimensional Array to One Dimensional Javascript Array
    'Developer    : Anand Venkatraman
    'Creation Date    : 03/31/2000
    '**************************************************

    'This function converts a VBScript Array to Javascript Array(One Dimensional array only)
    'Inputs are VBScript array and Javascript array name
    'For the sake of variable names "mismatch", "vb2js" is prefixed to all the variables
    'For eg. in ASP page you might call this function as "Call ConvertToJSArray(arrUserList,"arrUserList")
    'When this function is called immediately Javascript array is created and written to the web page
    'So we cannot use Response.Redirect after calling this function. You can View the Source of HTML page
    'to see the Javascript array.

    Function ConvertToJSArray1D(VBArray , ArrayName)

    Dim vb2jsRow , vb2jsStr, vb2jsi
    vb2jsRow = Ubound(VBArray,1)
    %>
    <SCRIPT LANGUAGE = 'JAVASCRIPT' >
    var vb2jsi
    <%=ArrayName%> = new Array(<%=vb2jsRow+1%>);
    for (vb2jsi=0; vb2jsi < <%=vb2jsRow+1%>; vb2jsi++)
    {
        <%=ArrayName%>[vb2jsi]= " "
    }
    </SCRIPT>
    <%
    Response.Write("<SCR"&"IPT LANGUAGE = 'JAVASCRIPT' >"&chr(13))
    for vb2jsi=0 to vb2jsRow
        vb2jsstr = "VBArray("&vb2jsi&")"
    %>    
        <%=ArrayName%>[<%=vb2jsi%>]= "<%=trim(eval(vb2jsstr))%>"
    <%
    Next
    Response.Write("</SCR"&"IPT>")
    End Function
    %>

    Second Include File

    <%
    '***************************************************
    'Name        : VB2JSarray2D.inc
    'Description    : Include File used to convert a VBScript Two Dimensional Array to Two Dimensional Javascript Array
    'Developer    : Anand Venkatraman
    'Creation Date    : 03/31/2000
    '***************************************************

    'This function converts a VBScript Array to Javascript Array(Two Dimensional array only)
    'Inputs are VBScript array and Javascript array name
    'For the sake of variable names "mismatch", "vb2js" is prefixed to all the variables
    'For eg. in ASP page you might call this function as "Call ConvertToJSArray(arrUserList,"arrUserList")
    'When this function is called immediately Javascript array is created and written to the web page
    'So we cannot use Response.Redirect after calling this function. You can View the Source of HTML page
    'to see the Javascript array.

    Function ConvertToJSArray2D(VBArray , ArrayName)

    Dim vb2jsRow, vb2jsCol , vb2jsStr, vb2jsi, vb2jsj
    vb2jsRow = Ubound(VBArray,1)
    vb2jsCol = Ubound(VBArray,2)
    %>
    <SCRIPT LANGUAGE = 'JAVASCRIPT' >
    var vb2jsi,vb2jsj
    <%=ArrayName%> = new Array(<%=vb2jsRow+1%>);
    for (vb2jsi=0; vb2jsi < <%=vb2jsRow+1%>; vb2jsi++)
    {
        <%=ArrayName%>[vb2jsi] = new Array(<%=vb2jsCol+1%>)
    for (vb2jsj=0; vb2jsj < <%=vb2jsCol+1%>; vb2jsj++) <%=ArrayName%>[vb2jsi][vb2jsj] = " "
    }
    </SCRIPT>
    <%
    Response.Write("<SCR"&"IPT LANGUAGE = 'JAVASCRIPT' >"&chr(13))
    for vb2jsi=0 to vb2jsRow
    for vb2jsj=0 to vb2jsCol
        vb2jsstr = "VBArray("&vb2jsi&","&vb2jsj&")"
    %>    
        <%=ArrayName%>[<%=vb2jsi%>][<%=vb2jsj%>] = "<%=trim(eval(vb2jsstr))%>"
    <%
    Next
    Next
    Response.Write("</SCR"&"IPT>")
    End Function

    %>


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Articles
    More By AnandV

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Driving Business Success with Rational Process Library

    Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance.
    FREE! Go There Now!


    NEW! Download a free trial of Lotus Quickr 8.0

    Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Developer for System i V7.1

    Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Software Analyzer V7.0

    Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase.
    FREE! Go There Now!


    NEW! Project and Portfolio Management Executive Resource Kit

    Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle.
    FREE! Go There Now!


    NEW! Rational Asset Manager eKit

    Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions.
    FREE! Go There Now!


    NEW! Webcast: Calling All Testers! Find Application Vulnerabilities Early in the Development Process Where they are Easier to Fix and Less Risky to your Business

    In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    FREE! Go There Now!


    NEW! Webcast: Striking the right balance between manual and automated testing

    Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP ARTICLES

    - Using MySQL with ASP
    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek