469,323 Members | 1,551 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

SSI with javacript - syntax problem.

HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page. they
are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.

Since the page does load fully I suspect that Its a small syntax problem but
I just don't know what.

can someone tell me what I am doing wrong?

--
Thanks in advance :)

Paul
Aug 30 '05 #1
17 1725
rf
Paul wrote:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page. they are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.


That should be a hint.

Count the 's and the "s in the above document.write call.

I see two 's but, oddly (pun intended), three "s. Three "s would usually
cause an unterminated string somewhere. " to open the string but no closing
". You are at the mercy of error correction.

I suspect the first " should not be there.

Cheers
Richard.
Aug 30 '05 #2
HI! thanks for responding. It still does not work. I see in source
view that it writes a one line then stops.

I being told that Includes need to happen on the server, this
include directive is being written out on the client by which time it's too
late to include.

Here is the link.
http://www.webcandesign.com/111/main_test_newnew.asp

How do load the page then?

Paul

"rf" <@invalid.com> wrote in message
news:dL******************@news-server.bigpond.net.au...
Paul wrote:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page.

they
are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.


That should be a hint.

Count the 's and the "s in the above document.write call.

I see two 's but, oddly (pun intended), three "s. Three "s would usually
cause an unterminated string somewhere. " to open the string but no
closing
". You are at the mercy of error correction.

I suspect the first " should not be there.

Cheers
Richard.

Aug 30 '05 #3

Paul wrote:
HI! thanks for responding. It still does not work. I see in source
view that it writes a one line then stops.

I being told that Includes need to happen on the server, this
include directive is being written out on the client by which time it's too
late to include.

Here is the link.
http://www.webcandesign.com/111/main_test_newnew.asp

How do load the page then?

Paul

"rf" <@invalid.com> wrote in message
news:dL******************@news-server.bigpond.net.au...
Paul wrote:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page.

they
are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.


That should be a hint.

Count the 's and the "s in the above document.write call.

I see two 's but, oddly (pun intended), three "s. Three "s would usually
cause an unterminated string somewhere. " to open the string but no
closing
". You are at the mercy of error correction.

I suspect the first " should not be there.

Cheers
Richard.


Hello Paul,

If you're trying to do SSI with javascript, you're going about it all
wrong. It's called Server Side Includes (SSI) for a reason. That being
that it happens on the server side. You can attempt to do Client Side
Includes, but believe me, that will get messy real fast. Here are some
general solutions:

For an ASP page:

<!--#include virtual="filename"-->
or
<!--#include file ="filename"-->

For a PHP page:
require("filename");
or
include("filename");

For a SHTML page:
<!--#include virtual="filename"-->
or
<!--#include file ="filename"-->

Hope this helps.

Aug 30 '05 #4
Paul schrieb:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page. they
are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.

Since the page does load fully I suspect that Its a small syntax problem but
I just don't know what.

can someone tell me what I am doing wrong?


Hi Paul,

when i take a look at the pagespurce, I see something different than posted:

document.write(<div id=DivExample>'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
....
</html>
</div>');

First of all: The text inside the () must be quoted (single or double), so it
should be

document.write('<div id=DivExample><!DOCTYPE HTML PUBLIC ...

The next thing: There must nor be a line break inside the string. YIf you want
to have breaks, you have to insert the breaks as \n (or \r\n for Windows-Style).
Strings have to be concatenated (correctly written??) with +:

document.write('<div id=DivExample><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01'
+ ' Transitional//EN">'
+ '<html>');

And the last thing: Why are you using JS-document.write and not inserting the
SSI directly:

<div id=DivExample><!--#include > virtual="/Include_Pages_Asp/Main.htm" --></div>

This (without the JS) should bring you to the wanted result.

Greetings,

Martin
Aug 30 '05 #5
ASM
Paul wrote:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>


<script language="JavaScript"> is uncorrect

a " (dble quote) is missing

<script type="text/javascript">
document.write('<div id="DivExample>"'+
'<!--#include virtual="/Include_Pages_Asp/Main.htm" -->'+
'<\/div>');
</script>

allways an anti-slash before a slash next after a '<'
or :
'<'+'/div>'

and ... what have you in your Main.htm ?

--
Stephane Moriaux et son [moins] vieux Mac
Aug 31 '05 #6
ASM said the following on 8/30/2005 7:55 PM:
Paul wrote:
HI! I am trying to dynamically add content into Div tags with the use
of JavaScript. it loads the page but adds a few characters. the script
is below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

<script language="JavaScript"> is uncorrect

a " (dble quote) is missing


Where? The script tag you quoted shows the deprecated language attribute
in quotes.
<script type="text/javascript">
document.write('<div id="DivExample>"'+
'<!--#include virtual="/Include_Pages_Asp/Main.htm" -->'+
'<\/div>');
</script>

allways an anti-slash before a slash next after a '<'
or :
'<'+'/div>'


And it still won't work. It is because the include has already occured,
or attempted to occur, before the script is ever executed.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 31 '05 #7
ASM
Paul wrote:
HI! thanks for responding. It still does not work. I see in source
view that it writes a one line then stops.

I being told that Includes need to happen on the server, this
include directive is being written out on the client by which time it's too
late to include.

Here is the link.
http://www.webcandesign.com/111/main_test_newnew.asp

How do load the page then?

once more : what's content of 'Main.htm' ?

because in the page is :

document.write(<div id=DivExample>'<!DOCTYPE HTML ... >

and a quote is yet missing ... !
and,
if there if a return carriage in 'Main.htm'
it will not work

You'ld have to set in 'Main.htm' :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"<br>'+
'"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">

note the quotes (') and plus (+)

so, in your JS :

document.write('<div id="DivExample">'+
'"/Include_Pages_Asp/Main.htm" --></div>');

to get in end

document.write('<div id="DivExample">'+
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"<br>'+
'"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd"><\/div>');
--
Stephane Moriaux et son [moins] vieux Mac
Aug 31 '05 #8
HI! thanks for the response. I am using it this form because I want to be
able to change the content. I want to be able to replace the include file
from a menu. Is there another way to do this without going this without
using the javascript in the way that I am using it?

Paul
"Martin Kurz" <in**@martinkurz.in-berlin.de> wrote in message
news:11***************@elch.in-berlin.de...
Paul schrieb:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page.
they
are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.

Since the page does load fully I suspect that Its a small syntax problem
but
I just don't know what.

can someone tell me what I am doing wrong?


Hi Paul,

when i take a look at the pagespurce, I see something different than
posted:

document.write(<div id=DivExample>'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01
Transitional//EN">
<html>
...
</html>
</div>');

First of all: The text inside the () must be quoted (single or double), so
it
should be

document.write('<div id=DivExample><!DOCTYPE HTML PUBLIC ...

The next thing: There must nor be a line break inside the string. YIf you
want
to have breaks, you have to insert the breaks as \n (or \r\n for
Windows-Style).
Strings have to be concatenated (correctly written??) with +:

document.write('<div id=DivExample><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01'
+ ' Transitional//EN">'
+ '<html>');

And the last thing: Why are you using JS-document.write and not inserting
the
SSI directly:

<div id=DivExample><!--#include >
virtual="/Include_Pages_Asp/Main.htm" --></div>

This (without the JS) should bring you to the wanted result.

Greetings,

Martin

Aug 31 '05 #9
HI! I don't the see the different between what you have shown me and what I
have done.

<!--#include virtual="/Include_Pages_Asp/Main.htm" -->

<!--#include virtual="filename"-->

I am using asp. I dont understand the difference that you are pointing out.
Paul
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

Paul wrote:
HI! thanks for responding. It still does not work. I see in source
view that it writes a one line then stops.

I being told that Includes need to happen on the server, this
include directive is being written out on the client by which time it's
too
late to include.

Here is the link.
http://www.webcandesign.com/111/main_test_newnew.asp

How do load the page then?

Paul

"rf" <@invalid.com> wrote in message
news:dL******************@news-server.bigpond.net.au...
> Paul wrote:
>> HI! I am trying to dynamically add content into Div tags with the use
>> of
>> JavaScript. it loads the page but adds a few characters. the script is
>> below.
>>
>> <script language="JavaScript">
>> document.write('<div id=DivExample>"<!--#include
>> virtual="/Include_Pages_Asp/Main.htm" --></div>');
>> </script>
>>
>> The characters that are added is right after the end of Main.htm page.
> they
>> are as follows.
>>
>> ');
>>
>> I also get this JavaScript error in IE
>>
>> Line: 48
>> Char:106
>> Error:Unterminated string constant.
>
> That should be a hint.
>
> Count the 's and the "s in the above document.write call.
>
> I see two 's but, oddly (pun intended), three "s. Three "s would
> usually
> cause an unterminated string somewhere. " to open the string but no
> closing
> ". You are at the mercy of error correction.
>
> I suspect the first " should not be there.
>
> Cheers
> Richard.
>
>


Hello Paul,

If you're trying to do SSI with javascript, you're going about it all
wrong. It's called Server Side Includes (SSI) for a reason. That being
that it happens on the server side. You can attempt to do Client Side
Includes, but believe me, that will get messy real fast. Here are some
general solutions:

For an ASP page:

<!--#include virtual="filename"-->
or
<!--#include file ="filename"-->

For a PHP page:
require("filename");
or
include("filename");

For a SHTML page:
<!--#include virtual="filename"-->
or
<!--#include file ="filename"-->

Hope this helps.

Aug 31 '05 #10
I wonder now is there is perhaps an easier way by creating a session
variable to load the string ( path of the include file) and then change the
string value via the menu . would work? this would mean the include file
would not to be modified and it would treated as normal include file. is
this correct?

Paul
"Randy Webb" <Hi************@aol.com> wrote in message
news:39********************@comcast.com...
ASM said the following on 8/30/2005 7:55 PM:
Paul wrote:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

<script language="JavaScript"> is uncorrect

a " (dble quote) is missing


Where? The script tag you quoted shows the deprecated language attribute
in quotes.
<script type="text/javascript">
document.write('<div id="DivExample>"'+
'<!--#include virtual="/Include_Pages_Asp/Main.htm" -->'+
'<\/div>');
</script>

allways an anti-slash before a slash next after a '<'
or :
'<'+'/div>'


And it still won't work. It is because the include has already occured, or
attempted to occur, before the script is ever executed.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly

Aug 31 '05 #11
ASM
Paul wrote:
HI! I don't the see the different between what you have shown me and what I
have done.


the differences are :

'virtual' is to use with a relative link
virtual="../folder/file.htm" : relative / page calling
virtual="/file.htm" : relative / root of site

'file' is to use with absolute link
file="http://sever/site/folder/page.htm"

--
Stephane Moriaux et son [moins] vieux Mac
Aug 31 '05 #12
ASM
Paul wrote:
HI! thanks for the response. I am using it this form because I want to be
able to change the content. I want to be able to replace the include file
from a menu. Is there another way to do this without going this without
using the javascript in the way that I am using it?


the change of content with SSI can only be made by loading on server

You can use in SSI server request about url of document
then
get dynamicaly by SSI what it is expected

The JS will run after SSI instructions did
(and here : no need of JS)

here is a plan with SSI only
supposing sent url is this form :
'page.shtml?docType=4T'
or
'page.shtml?docType=41T'
file 'page.shtml' :

<!--#set var="Gotn" value="$QUERY_STRING" -->

<!--#if expr="$Gotn = /. 4T ./" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">

<!--#elif expr="$Gotn = /. 4F ./" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/frameset.dtd">

<!--#elif expr="$Gotn = /. 4S ./" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/strict.dtd">
<!--#elif expr="$Gotn = /. 41T ./" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

<!--#endif -->

<html>
<head>
....
</html>
SSI instruction :

<!--#if expr="$Gotn = /. 4T ./" -->

verify if '4T' exists inside value of ssi variable : $Gotn
that's : is string '4T' in url of called page ?

if yes, following html code is writen on page

if not, is ? :
<!--#elif expr=" ... blah ...

You can use this procedure to create on loading your menus

--
Stephane Moriaux et son [moins] vieux Mac
Aug 31 '05 #13
ASM
Randy Webb wrote:
ASM said the following on 8/30/2005 7:55 PM:

a " (dble quote) is missing

Where? The script tag you quoted shows the deprecated language attribute
in quotes.
<script type="text/javascript">
document.write('<div id="DivExample>"'+ ^^^
here : -------------|
'<!--#include virtual="/Include_Pages_Asp/Main.htm" -->'+
'<\/div>');
</script>

allways an anti-slash before a slash next after a '<'
or :
'<'+'/div>'

And it still won't work. It is because the include has already occured,
or attempted to occur, before the script is ever executed.


no, it is because what is to include is not a string
( doc type in 2 lines I think )

--
Stephane Moriaux et son [moins] vieux Mac
Sep 1 '05 #14
HI! And that's why I used virtual because its from the virtual root. I don't
understand why you are pointing it out then.

Paul
"ASM" <st*********************@wanadoo.fr.invalid> wrote in message
news:43***********************@news.wanadoo.fr...
Paul wrote:
HI! I don't the see the different between what you have shown me and what
I have done.


the differences are :

'virtual' is to use with a relative link
virtual="../folder/file.htm" : relative / page calling
virtual="/file.htm" : relative / root of site

'file' is to use with absolute link
file="http://sever/site/folder/page.htm"

--
Stephane Moriaux et son [moins] vieux Mac

Sep 1 '05 #15
HI! no what I meant was to create session var to hold the string value on
the include name, not the content of the include. and in the body on the asp
file it would just insert the string name and the browser would replace it
with the include value. this is what I meant. but what I am not sure of the
is if the includes get insert before the <% %> get done. would it help to
put buffer.s=true for the asp file?

--

Paul
"ASM" <st*********************@wanadoo.fr.invalid> wrote in message
news:43***********************@news.wanadoo.fr...
Randy Webb wrote:
ASM said the following on 8/30/2005 7:55 PM:

a " (dble quote) is missing

Where? The script tag you quoted shows the deprecated language attribute
in quotes.
<script type="text/javascript">
document.write('<div id="DivExample>"'+ ^^^
here : -------------|
'<!--#include virtual="/Include_Pages_Asp/Main.htm" -->'+
'<\/div>');
</script>

allways an anti-slash before a slash next after a '<'
or :
'<'+'/div>'

And it still won't work. It is because the include has already occured,
or attempted to occur, before the script is ever executed.


no, it is because what is to include is not a string
( doc type in 2 lines I think )

--
Stephane Moriaux et son [moins] vieux Mac

Sep 1 '05 #16
ASM
Paul wrote:
HI! no what I meant was to create session var to hold the string value on
the include name, not the content of the include.
and in the body on the asp
it is your *.asp
by its conditions relatively to url asked
wich will write the right value (string) in the html code of page

if an external file is needed to decide the value string,
it is inside this *.asp that you have to include external file
in right place

if you did your menus are severa and in separate external files
the *.asp will include the correct one of this files

and browser knows anything of that
server send only html with no more SSI or ASP code
file it would just insert the string name and the browser would replace it
with the include value.
Browser has not to replace this value
The value has to be set ahead on server
this is what I meant. but what I am not sure of the
is if the includes get insert before the <% %> get done. would it help to
put buffer.s=true for the asp file?


if you did read what I give as SSI example
in post : "[HS SSI] SSI with javacript - syntax problem."
and you need to include in SSI a particular file from several :

file 'page.shtml' :

<!--#set var="Gotn" value="$QUERY_STRING" -->
<!--#if expr="$Gotn = /. 4T ./" -->
<!--#include virtual="/doctypes/type_4t.htm" -->
<!--#elif expr="$Gotn = /. 4F ./" -->
<!--#include virtual="/doctypes/type_4f.htm" -->
<!--#endif -->

no need of JS

--
Stephane Moriaux et son [moins] vieux Mac
Sep 1 '05 #17
ASM said the following on 8/31/2005 8:38 PM:
Randy Webb wrote:
ASM said the following on 8/30/2005 7:55 PM:

a " (dble quote) is missing


Where? The script tag you quoted shows the deprecated language
attribute in quotes.
<script type="text/javascript">
document.write('<div id="DivExample>"'+
^^^
here : -------------|

I am not sure I see what your ^^^ is pointing at, but the issue of " is
not relevant unless it is later used to be part of the quoted text to
JS. Meaning : document.write('anything inside the single quote,
including double quotes " , do not have to be paired. It only matters if
there is an \' inside, as it has to be escaped')

What you seem to have added was an extra " before the id, but you didn't
put it after the ID, you left the errant " outside the > but its still
irellavant.
'<!--#include virtual="/Include_Pages_Asp/Main.htm" -->'+
'<\/div>');
</script>

allways an anti-slash before a slash next after a '<'
or :
'<'+'/div>'


And it still won't work. It is because the include has already
occured, or attempted to occur, before the script is ever executed.

no, it is because what is to include is not a string
( doc type in 2 lines I think )


No, it is because the include has alread occured, or attempted to occur,
before the script is ever executed.

Browser requests page.
Server assembles page, including included.
Server sends page to browser.
Browser processes page.
JS writes an include statement that was desired to be included in step 2.
Browser displays page, without the include because the server has
already finished step 2.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 1 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Terry | last post: by
3 posts views Thread by a_nona_mouse | last post: by
4 posts views Thread by weiwei | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.