...

View Full Version : include file



esthera
05-10-2004, 03:45 PM
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?

liorean
05-10-2004, 06:04 PM
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?

esthera
05-10-2004, 06:30 PM
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.

glenngv
05-11-2004, 03:41 AM
We need to see what's inside getstyles.asp so we can see the problem.
And please also post here the error message displayed.

esthera
05-11-2004, 05:57 AM
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

glenngv
05-11-2004, 06:49 AM
Is that all the content? What errors are thrown?

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

esthera
05-11-2004, 07:01 AM
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.

glenngv
05-11-2004, 08:33 AM
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:


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>

esthera
05-11-2004, 08:44 AM
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?

glenngv
05-11-2004, 09:16 AM
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'getstyles.asp';
document.getElementsByTagName('head')[0].appendChild(script);

esthera
05-11-2004, 10:09 AM
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?

glenngv
05-11-2004, 10:49 AM
A link to your site or attachment of related files is the better way to help you.

esthera
05-11-2004, 11:17 AM
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.

glenngv
05-12-2004, 03:00 AM
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.


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;'
}
]

esthera
05-12-2004, 06:40 AM
that was my first try but didn't work.

glenngv
05-12-2004, 08:21 AM
How did you do it?

esthera
05-12-2004, 08:25 AM
my first try was just renaming ediornew.js to editornew.asp and changing the name in the first file. This did not load the file.

Is there something I was missing. I can try again.

glenngv
05-12-2004, 09:38 AM
How does the "editornew.asp" look then (particularly the "this.fontstyles" part)?

esthera
05-12-2004, 09:46 AM
I left it exactly as it was and just renamed the file.
If my test would have worked I would have added the asp code to the .asp file.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum