Using VBScript with JavaScript
Get Started:
You Can Get Javascript and Vbscript to start from the Same Sheet of Music. Consider The Script Below.
<% @ Language = "javascript"%>
Function jsgreeting ()
{
Return "Greetings from a javascript function";
}
Script>
Function vbgreeting ()
Vbgreeting = "Greetings from a vbscript function"
END FUNCTION
Function Todollars (x)
Todollars = Formatcurrency (x)
END FUNCTION
Script>
<%
VAR A = 2;
VAR B = 2;
VAR C = add (a, b)
C = "(Two Numbers Areadded by JavaScript,"
C = "and the formatted Into currency by vbscript.)"
Function add (x, y)
{
Result = x y;
Result = Todollars (Result);
Return Result;
}
Response.write (" / r")
Response.write (jsgreeting () "
/ r")
Response.write (vbgreeting () "
/ r")
Response.write (C "
/ R")
Response.write (" html> / r")
%>
Click Here to Run The Script in a New window.
Runat:
Let me pick this apart from top to bottom. Directly Below Is A Simple Stand-Alone JavaScript.
Function jsgreeting ()
{
Return "Greetings from a javascript function";
}
Script>
This Looks Like Any Simple JavaScript You Might Find on The Client Side Except for this Little Number: Runat = "Server".
The RUNAT attribute tells the server to execute on the server, so the client never sees it. You can also set RUNAT = "Client" in which case the Script would be passed along as-is to the web browser.By the way,
SHOULD NOT BE PUT INSIDE ASP FLAGS.
Take a look at the vbscript Directly Below.
Function vbgreeting ()
Vbgreeting = "Greetings from a vbscript function"
END FUNCTION
This Vbscript does exactly the Same Thing as its javascript counterpart. There's Nothing Terribly Special About IT.
The Invocation:
There IS, HOWEVER, SOMETHING Special About The Following Vbscript.
Function Todollars (x)
Todollars = Formatcurrency (x)
END FUNCTION
The Above Function Will Take An Argument From A JavaScript Function. The IT Will Return The Appropriate Value To The JavaScript Function. Let Me Show How Function Todollars (x) is invoked.
Function add (x, y)
{
Result = x y;
Result = Todollars (Result);
Return Result;
}
Function Add (x, y) IS A JavaScript Function. Halfway Into The Function, There I the Following Line:
Result = Todollars (Result);
The Above Line Is in Fact A Call from a JavaScript Function to Invoke A Vbscript Function. How About That!
WARNING:
Just One Cavet. When You Create Scripts Using The Runat Attribute The. I Won't Go Into It Now, Because The Order of Execution Is Situational.