WebRef Update: Featured Article: Mix and Match: Using VBScript to define and control JavaScript on Active Server Pages | 2 | WebReference

WebRef Update: Featured Article: Mix and Match: Using VBScript to define and control JavaScript on Active Server Pages | 2


Using VBScript to define and control JavaScript with ASP

Let's say the Charge value in our Payment History object is 35; at runtime the first time through the loop, the line will evaluate to:

ArryTotAmt[1] = 35;

The For-Next loop will continue to run, writing lines of JavaScript, incrementing the array counter, until PaymentHistory.Count is reached. For example, assuming the 2nd Charge item in our PaymentHistory object has a value of 18, then the 2nd time through the loop

arryTotAmt[<%=i%>]=<%=Cstr(PaymentHistory.Item(i).Charge)%>;

will evaluate to:

ArryTotAmt[2] = 18;

Once my JavaScript array has been populated, I can then spawn a window and draw my graph.

Here is another example of embedding a VbScript variable in a JavaScript function. I need to pass the URL of the window that is going to be spawned, but the location is determined by which server and virtual root the page is run from. We hold that information in a variable called "baseurl". So the JavaScript line to spawn the new window looks something like this:

var remote = open("<%=baseurl%>/Scripts/graph.asp","Graph", "fullscreen=yes, location=no, menubar=yes, resizable=yes, status=no, toolbar=yes, dependent=no, scrollbars=yes");

Again note the special tags <% %> used to mark the beginning and end of our embedded VBscript variable.

To draw my simple bar chart, I now simply use my array value to determine the height of a holder image.

fnDrawGraph(){

remote.document.write("<table border='1'><tr>");

//write the graph images

for (k=arryTotAmt.length - 1; k>0; k--){ remote.document.write("<td align=bottom align=center> <img src='../images/graph.gif' width=30 height=" + Math.round(parseFloat(arryTotAmt[k])) + " alt=" + arryTotAmt[k] + "></td>>); } remote.document.write("</tr><tr>");

}

The actual graph function I eventually used has a few more features, but the above code was the core of the solution. An example of the graph that was actually spawned can be found at www.webreference.com/art/000113bargraph.gif

So, as we have seen here, not only can VBScript be used to write standalone functions, it can be used to extend, and determine the characteristics of JavaScript.

Author Jerry Gray works on the Internet Application Development Team at Consumers Energy in Jackson, MI. Jerry is married, with two daughters, and holds a BS in CIS/Mgt. and a MS in Admin. Science. When not writing code, Jerry says that you can find him "playing Multi-Player BattleTech or Legends of Kesmai at Gamestorm. ;-)"

Contact Jerry at: [email protected]

Previous: Bar Chart Beginning

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

https://www.internet.com

Comments are welcome
Written by Jerry Gray and

Revised: May 10, 2000

URL: https://webreference.com/new/vbscript2.html