Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    297
    Thanks
    10
    Thanked 0 Times in 0 Posts

    'Include files' in a javascript

    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"-->");

    </SCRIPT>

    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?

    Regards

    Gary

  • #2
    Regular Coder
    Join Date
    May 2003
    Location
    Manassas, VA, USA
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.)

    -Andrew

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    617
    Thanks
    1
    Thanked 20 Times in 20 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    297
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Hi,

    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!

    Gary


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •