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! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    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! Krugle, developerWorks, and code search

    Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users.
    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! Test terminal-based applications with Rational Functional Tester

    Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily.
    FREE! Go There Now!


    NEW! The dirty dozen: preventing common application-level hack attacks

    As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Manual Tester V7.0.1

    Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Connectivity

    Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic.
    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: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    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-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek