0

How would I insert some JavaScript code into a block of ASP code? i.e. to do it the other way round you would put:

var somejavascriptvariable = <%= someasp %>;

any help?

2
  • possible duplicate of Reference: Why does the PHP (or other server side) code in my Javascript not work? Commented Feb 3, 2014 at 10:39
  • The problem is that Classic ASP is server-side whereas JavaScript is client side. You can use JavaScript to furnish a call to a Classic ASP page, but unlike the example you gave (var somejavascriptvariable = <%= someasp %>;) JavaScript will not be able to modify the script on the server side. Commented Feb 3, 2014 at 13:33

1 Answer 1

1

It would help if you provided some code to show us exactly what you're trying to do. Are you talking about client side javascript here as per Westie's comment? If you're using classic asp to output js then you can always put it in a response.write statement, but the syntax would be horrible, given that you would probably have loads of double quotes to escape.

You can use JavaScript as your server side scripting language in place of VBScript. There are two ways of doing this. If you start a page with the line

<%@language="javascript"%>

Then you can use js within your <% %> tags instead of vbs.

Alternatively you can use it in a page which mainly uses vbs as follows, note the use of runat="server"

<%@language="VBScript"%>
<html>
<head>
<script type="text/javascript" language="javascript" runat="server">
    var HelloWorld = "hello world";
</script>
<title>Title</title>
</head>
<body>
<%= HelloWorld %>
</body>
</html>>
Sign up to request clarification or add additional context in comments.

1 Comment

I think he means client side JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.