Re: Javascript write with an include file using .shtml...
by Andrew McFarland <aamcf(at)aamcf.co.uk>
|
Date: |
Mon, 07 Jan 2002 01:13:51 +0000 |
To: |
hwg-languages(at)hwg.org |
In-Reply-To: |
hotmail |
|
todo: View
Thread,
Original
|
|
At 19:00 06/01/02 -0500, Michael Boyer wrote:
>// document.write("'#429AFC' id='day" + days + "' height='90'
>valign='top'><b>" + days + "<\/b><BR><!--#include file='test" + days +
>".txt' --><\/td>");
>days++; // Increment the day of the month counter.
>
>I thought this would result in 'test1.txt' in cell data 1, 'test2.txt' in
>cell data 2, and so on, but I get the error:
>
>"[an error occurred while processing this directive]" in the cell data.
>I've tried putting the quotations in different places, but to no avail--in
>fact it crashed my browser at one change.
All server side includes are done on the server; all JavaScript (in this
case) is done on the browser.
Basically, what this boils down to is the server only sees
<!--#include file='test" + days + ".txt' -->
as a server side include, which isn't valid, so you get the error message
embedded in the document.write.
The browser then receives
document.write("'#429AFC' id='day" + days + "' height='90'
valign='top'><b>" + days + "<\/b><BR>[an error occurred while processing
this directive]<\/td>")
which is obviously not what you want.
One solution might be
<script type="text/javascript">
<!--#include file='javascript.stuff'-->
//[start of javascript loop]
// document.write("'#429AFC' id='day" + days + "' height='90'
valign='top'><b>" + days + "<\/b><BR>" + stuff[days] + "<\/td>");
days++; // Increment the day of the month counter.
//[end of javascript loop ]
</script>
The file javascript.stuff should contain a JavaScript array of all the
required text
For example, if days could be 1 2 or 3, javascript.stuff would be:
// Start of file
var stuff = new Array();
stuff[1] = "day one text";
stuff[2] = "day two text";
stuff[3] = "day three text";
// end of file
The above is pretty sketchy, but it is 1AM over here :-)
Andrew
--
http://aamcf.co.uk/
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA