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?

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
howdybaby
  • 287
  • 1
  • 4
  • 15
  • possible duplicate of [Reference: Why does the PHP (or other server side) code in my Javascript not work?](http://stackoverflow.com/questions/13840429/reference-why-does-the-php-or-other-server-side-code-in-my-javascript-not-wor) – Quentin Feb 03 '14 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. – Paul Feb 03 '14 at 13:33

1 Answers1

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>>
John
  • 4,658
  • 2
  • 14
  • 23