spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / new / vbscript

Mix and Match: Using VBScript to define and control JavaScript on Active Server Pages

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

In the course of my Web page work I often have used JavaScript and VBScript on Active Server Pages (ASP). While searching the Web for references to help solve programming problems, it is easy to find pages to give examples on using one or the other, but rarely do you see information regarding using them both together.

Using VBScript to control JavaScript can be as simple as using the VBScript to determine whether the JavaScript will be presented to the client browser at all. For instance, you may decide that unless a browser is at least compatible with Mozilla version 4, a given JavaScript function will not be written. In this example, we check the browser information sent by the client before writing our function.

        <%strUA = Request.ServerVariables("HTTP_USER_AGENT")
          If InStr(strUA,"Mozilla/4") then%>
             Function fnMyNewFunction(){
              document.write("This is not a test.");
              }
          <%End If%>

Those of you familiar with VBScript know that the tags <% %> mark the beginning and end of a VBScript, the contents of which are interpreted at the time the page is presented to the browser. If the client browser is not Mozilla 4 compatible, then the fnMyNewFunction is never written, and the client browser never even sees that it exists.

I recently had a more difficult challenge where I was asked to create a bar chart that displayed customer account history. The constraints were 1.) spawn a new page, and 2.) use an existing object that had already been populated with data. Since the project was written specifically for a client, I can't give you the full code listing, but I can walk you through the logic of the development process.

I decided I would populate a JavaScript array with data from the existing VB object, then use that array to determine the height of my images in my bar chart. Then using JavaScript, I would display the chart in a new window. (For more on creating new windows see "Window Spawning and Remotes" - webreference.com/js/column7).

First, using JavaScript, I declare the array I want to populate:

        var arryTotAmt = new Array;

Then, using a VBscript For-Next loop, I populate the array with the values from my VB object. In this example, my VB object is named "PaymentHistory". It has already been created, and populated with values from my database, and has two important properties: "Count", which contains the total number of records in the object, and "Item", which is the nth instance of a record. Our PaymentHistory object contains many different fields associated with customer accounts, but for the purposes of our graph we are only interested in a property called "Charge". The Charge property of my PaymentHistory object contains the actual monthly value I want to put into my JavaScript array.

        <% for i = 1 to PaymentHistory.Count%>
          arryTotAmt[<%=i%>]=<%=Cstr(PaymentHistory.Item(i).Charge)%>;
        <%next%>

Next: Another Example

This article originally appeared in the January 13, 2000 edition of the WebReference Update Newsletter.


http://www.internet.com

Comments are welcome
Written by Jerry Gray and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior

Revised: May 10, 2000

URL: http://webreference.com/new/vbscript.html