ASP
  Home arrow ASP arrow Converting VBScript Array to Javascript Ar...
Iron Speed
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 20
    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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    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!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Download the free Web Application Security eKit

    Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications.
    FREE! Go There Now!


    NEW! Evaluate Rational Host Access Transformation Services (HATS) Toolkit V7.1

    Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications.
    FREE! Go There Now!


    NEW! Harnessing the power of SQL and Java for high performance data access

    Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z: Architecture

    Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server.
    FREE! Go There Now!


    NEW! Rational Testing eKits

    Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing.
    FREE! Go There Now!


    NEW! Successful Change and Release Management for .NET

    Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    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

    - 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
    - Easy Error Management





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway