How to mix Classic ASP and Server-Side Javascript

Sometimes I need to fix some old Classic ASP applications or add small new features to them.

Because I do Javascript or C# every day for new apps, it hurts to get back to VBScript for these old apps!

That’s why I try to do these using Server-Side Javascript instead.  But wait, how can I mix NodeJS and VBScript?  The answer is, you can’t.  But, there was Server-Side JS before NodeJS exists!

Now, look at this.

You have a ASP Classic site like this:

<% dim product : product = "apple"
response.write product %>

And you need to create a new function to get the product name.

But, you don’t want to do it in VBScript, because you prefer JavaScript.

All you need to do is to create an “include” file, in pure javascript, like this:

function getProduct(){
	var product = "apple";
	return product;

And, add it to your existing ASP file:

<script runat="server" language="javascript" src="" ></script>

Finally, you can fix your existing code like this:

<% dim product : product = "apple"
response.write getProduct %>

Yes, the VB code can call JS function directly.
Also, your JS code can also use already existing VBScript functions and variables.

2 thoughts on “How to mix Classic ASP and Server-Side Javascript”

  1. This is cool Frederick but wouldn’t getProduct return the function rather than invoking it? getProduct() would return the result from the function. Also you would no longer need to define product in the ASP page because that is no longer used.

    1. Because the call is from vbscript, so you don’t need to use (). But I think both works. And you are right, I copied the first sample and I forgot to remove the “dim product” ! Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.