ASP program



In ASP, you can call JavaScript subroutines through VBScript and vice versa.


Subroutines

ASP source code can contain subroutines and functions:

Examples

<!DOCTYPE html>
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>

<p>Result: <%call vbproc(3,4)%></p>

</body>
</html>

Run instance»

Click the "Run instance" button to view the online instance

Write the line <%@ language="language" %> in <html> ; Above the tag, you can use another scripting language to write subroutines or functions:

Example

<%@ language="javascript" %>
<!DOCTYPE html>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>

<p>Result: <%jsproc(3,4)%></p>

</body>
</html>

Run Example»

Click "Run Example" button to view online examples



The difference between VBScript and JavaScript

When calling VBScript or JavaScript subroutines from an ASP file written in VBScript , you can use the "call" keyword, followed by the subroutine name. If a subroutine requires parameters, the parameters must be enclosed in parentheses when using the "call" keyword. If you omit the "call" keyword, the parameters do not have to be enclosed in parentheses. If the subroutine has no parameters, the parentheses are optional.

When calling a VBScript or JavaScript subroutine from an ASP file written in JavaScript, you must use parentheses after the subroutine name.


tryitimg.gif

More examples

Use VBScript to call a subroutine
This example demonstrates how to call a VBScript subroutine and JavaScript in an ASP file subroutine.