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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: include file

  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts

    include file

    I have a big file.js file with many javascript functions.
    Within these functions I want to include another file. (asp to bring from the db to the js file)
    I tried
    <script language="javascript" src="getstyles.asp"></script>

    but it gave me an error.
    It is in the middle of a javascript function.
    Is there another way to do this?

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    What kind of error? What does the code look like? What dependencies does it have? Are you sending it as 'application/x-javascript', 'text/javascript', 'text/ecmascript' or something else? What browser did you use? Have you tried another browser?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    my include code is
    <script language="javascript" src="getstyles.asp"></script>
    It is in middle of a function.

    In my second page (getstyles.asp) I use document.write to write out javascript code.

    What could be the problem? My page does not load properly as if the code is not there.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    We need to see what's inside getstyles.asp so we can see the problem.
    And please also post here the error message displayed.

  • #5
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    This is get styles:

    document.write ("this.fontstyles = [")
    document.write ("{ name: 'tGeneva 14 px', className: 'aGeneva2', classStyle: 'color: #0000ff;FONT-FAMILY: Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 14px;TEXT-DECORATION: none;' },")
    document.write ("{ name: 'tGeneva 22 px', className: 'aGeneva3', classStyle: 'color: #0050A4;FONT-FAMILY: Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 22px;TEXT-DECORATION: none;' } ")
    document.write("];")

    I am using internet explorer. It gives me a javascript error and won't load the page because it has a problem in the function the include is in. If I take out this line of code
    <script language="javascript" src="getstyles.asp"></script>
    and put the code (from get styles) directly in the first js file without document.write- it works. (I need it to be in another file as I want to get the info from a database using asp)

    Please help

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Is that all the content? What errors are thrown?

    Another alternative is to use SSI
    <script type="text/javascript">
    <!--#INCLUDE FILE="getstyles.asp"-->
    </script>

  • #7
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    If I do this
    <script type="text/javascript">
    <!--#INCLUDE FILE="getstyles.asp"-->
    </script>
    I still get the same error. The error is object expected. -- one thing I fogot to mention is the file that I am tring to include from is included in another file as a .js file.

    If I just do the <!--#INCLUDE FILE="getstyles.asp"--> without the script tag I don't get an error but the code is not executing as my page is not displaying it properly (acting as if those lines of code are missing.

    Thanks for your help.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Ok, I'm now seeing what you did wrong. You are writing javascript statements using document.write and you expect that those statements are treated as js expressions that can be executed. What you need to do is to remove the document.writes in the getstyles.asp and just embed the data that come from the database just like the way you embed server-side data inside HTML tags. See sample below:
    Code:
    this.fontstyles = [
      { name: '<%=name%> 14 px', className: '<%=className%>', classStyle: 'color: #0000ff;FONT-FAMILY: Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 14px;TEXT-DECORATION: none;' 
      },
      { name: '<%=name%> 22 px', className: '<%=className2%>', classStyle: 'color: #0050A4;FONT-FAMILY: Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 22px;TEXT-DECORATION: none;' 
      }
    ]
    Then in the head tag:

    <head>
    <script type="text/javascript" src="getstyles.asp"></script>
    </head>

  • #9
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    the only problem is I wanted to include this text in the middle of a js function-
    Is this possible. Can I put the script tag in the middle of the function?

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'getstyles.asp';
    document.getElementsByTagName('head')[0].appendChild(script);

  • #11
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    There is no error now but it isn't loading the code.
    (from getstyles.asp -- I put it in getstyles.asp without the document.write)

    Any other ideas?

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    A link to your site or attachment of related files is the better way to help you.

  • #13
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    okay attached are the files. (Not the images though)
    You can see an example at http://www.familyaccountant.com/news/example.html

    The problem is in editornew.js line 136.
    This is a wysywg editor from htmlarea that I am customizing.
    The example.html calls the functions in editornew.js.
    In editornew.js I want to include getstyles.asp (in the middle of the function)

    Thanks for your help.
    Attached Files Attached Files

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    The easiest and fastest solution is to rename editornew.js to editornew.asp and then just embed in it whatever server-side data are dynamic.
    Code:
    this.fontstyles = [
      { name: '<%=name%> 14 px', className: '<%=className%>', classStyle: 'color: #0000ff;FONT-FAMILY: Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 14px;TEXT-DECORATION: none;' 
      },
      { name: '<%=name%> 22 px', className: '<%=className2%>', classStyle: 'color: #0050A4;FONT-FAMILY: Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 22px;TEXT-DECORATION: none;' 
      }
    ]

  • #15
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    that was my first try but didn't work.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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