This really ought to be asked on an ASP list but I'll try to explain.

On Wed, Dec 10, 2008 at 3:48 AM, JQueryProgrammer
<[EMAIL PROTECTED]> wrote:
>
> Sorry for the spam. Actually my issue is that I am trying to keep my
> html file neat and tidy by putting all my javascript code in a
> separate js file.

Believe me: sometimes ya gotta add some inline JS. I know, it's fugly.


> But my javascript code refers to some server side
> variable values which exists in an asp file. I have included that asp
> file in my main asp file along with the js file. But the js file
> dosn't seems to get server variable values. Here is a broad view of my
> code.
>
> mainpage.asp
> ----------> <!--#include virtual = "/mywebsite/child1.asp" -->
> ----------> <script type="text/javascript" src="child1.js"></script>
>
> child1.asp
> ----------> CONST myvar = 100

Is it CONST or VAR? It's probably not worth sidetracking you at this point but,
anyway ...


> child1.js
> ----------> alert(<%= myvar%>);

I think you need to step back and re-think this process. Your
child1.js file is not read by
the ASP interpreter. Thus, your <%= %> tags are meaningless therein.
The only thing
that reads that JS file is whatever browser that downloaded it. And
its JS engine doesn't know
or care about myvar.

What you should be aiming for is to have ASP (on the server) write
some text which will be
sent to the browser where it will (hopefully) be interpreted by the
browser's JS engine.

So:

child1.asp (let's say myservervalue = 'foobar')
---------------

// this should look something like the following:
// (is this even a real ASP comment?)

<script type="text/javascript">
var myvalue = "<%= myservervalue %>";
</script>
<script type="text/javascript" src="child1.js"></script>

The ASP script will (again, hopefully) resolve the <%= myservervalue
%> to some string. When the browser
fetches the page its JS interpreter will see:

var myvalue = "foobar";

Accordingly, the page will now  have a variable named, "myvalue" which
is, "foobar".


child1.js
------------

alert(myvalue);

The variable that was declared is called, "myvalue" not "<%= myvalue
%>". We're on the Javascript Ranch
now. No need for the flappy tags. You should see a bright, shining
"foobar" alert.

If the page reaches the browser and it still has the <% %> business
(view source), it's not working.

Reply via email to