View Full Version : 'Include files' in a javascript

Gary Williams
06-10-2003, 04:28 PM
Hi All,

If I write this:

<!--#include file="f1.asp"-->

in the body of an .htm or .asp page, the contents of f1.asp displays in all its glory. Hooray!

However, if I insert the following script in the body of an .htm or .asp page:

<SCRIPT LANGUAGE="JavaScript1.2">

document.write("<!--#include file="f1.asp"-->");


I get error messages.

I have written the javascript to decide which of a set of 'include file' is to be displayed but I can't get the above script ot work. Where have I gone wrong?



06-10-2003, 04:46 PM
If you look at the source of the page when you get the error, does it show anything? It may just be that it's outputting text in the wrong format (i.e., it has quotes that need to be changed or escaped.)


06-10-2003, 04:52 PM
I think it's happening too late. The .asp stuff should occur on the server, long before the client-side JavaScript gets a chance to write the 'include' line.

06-10-2003, 05:01 PM
jalarie is correct. The <-- #include --> and the code in your f1.asp file are treated as ASP and need to be executed before everything else.

Are you trying to do a conditional include statement or are you trying to include some javascript? There are separate ways to accomplish both of these, if that is what you are trying to do.

Gary Williams
06-10-2003, 05:18 PM

Yes, I should have spotted that one.

This is what I am trying to achieve.

I have 5 paragraphs of text that need to be displayed on one page.

If condition 1 is true, display all 5 paragraphs.

If condition 2 is true, display only paragraphs numbered 1, 2, 3.

I thought using includes might be suitable, but not anymore!