Click to See Complete Forum and Search --> : Invalid syntax help!


jrthor2
04-02-2003, 10:23 AM
Why do I get an invalid syntax in the follosing code? It points to the lnes in bold below


<script language="JavaScript1.2" type="text/javascript">
v_font='arial,helvetica,sans-serif';
v_fontSize='12px';
v_fontSizeNS4='11px';
v_fontWeight='normal';
v_fontColor='#330099';
v_textDecoration='none';
v_fontColorHover='#990033';// | won't work
v_textDecorationHover='underline';// | in Netscape4
v_bgColor='#d7d7ff';//set [='transparent'] for transparent
v_top=0;// |
v_left=0;// | defining
v_width=150;// | the box
v_height=60;// |
v_paddingTop=2;
v_paddingLeft=2;
v_position='relative';//absolute or relative
v_timeout=2500;//1000 = 1 second
v_slideSpeed=30;
v_slideDirection=0;//0=down-up;1=up-down
v_pauseOnMouseOver=false;
v_content=[
</script>
<script src="/cgi-bin/newspro/News_Scroller.js">
</script>
<script language="JavaScript1.2" type="text/javascript">
];
// THE SERIOUS SCRIPT - PLEASE DO NOT TOUCH
v_ua=navigator.userAgent;v_nS4=document.layers?1:0;v_iE=document.all&&!window.innerWidth&&v_ua.indexOf("MSIE")!=-1?1:0;v_oP=v_ua.indexOf("Opera")!=-1&&document.clear?1:0;v_oP4=v_ua.indexOf("Opera")!=-1&&!document.clear;v_kN=v_ua.indexOf("Konqueror")!=-1&&parseFloat(v_ua.substring(v_ua.indexOf("Konqueror/")+10))<3.1?1:0;v_count=v_content.length;v_s1=1;v_cur=1;v_cl=0;v_d=v_slideDirection?-1:1;v_TIM=0;v_fontSize2=v_nS4&&navigator.platform.toLowerCase().indexOf("win")!=-1?v_fontSizeNS4:v_fontSize;v_canPause=0;function v_getOS(a){return v_iE?document.all[a].style:v_nS4?document.layers['v_container'].document.layers[a]:document.getElementById(a).style};function v_start(){var o=v_getOS('v_1');if(!o)return;if(v_iE||v_oP){if(o.pixelTop==v_paddingTop){v_canPause=1;if(v_count>1)v_TIM=setTimeout("v_canPause=0;v_slide()",v_timeout);return};o.pixelTop-=v_d;if(v_oP&&o.visibility.toLowerCase()!='visible')o.visibility='visible';setTimeout("v_start()",v_slideSpeed);return};if(parseInt(o.top)==v_paddingTop){v_canPause=1;if(v_count>1)v_TIM=setTimeout("v_canPause=0;v_slide()",v_timeout);return};o.top=parseInt(o.top)-v_d;setTimeout("v_start()",v_slideSpeed)};function v_slide(){var o=v_getOS('v_'+v_cur);var o2=v_getOS('v_'+(v_cur<v_count?v_cur+1:1));if(!o||!o2)return;if(v_iE||v_oP){if(o.pixelTop==v_paddingTop*2-v_height*v_d){if(v_oP)o.visibility='hidden';o.pixelTop=v_height*v_d;v_cur=v_cur<v_count?v_cur+1:1;v_canPause=1;v_TIM=setTimeout("v_canPause=0;v_slide()",v_timeout);return};o.pixelTop-=v_d;if(v_oP&&o2.visibility.toLowerCase()!='visible')o2.visibility='visible';o2.pixelTop-=v_d;setTimeout("v_slide()",v_slideSpeed);return};if(parseInt(o.top)==v_paddingTop*2-v_height*v_d){o.top=v_height*v_d;v_cur=v_cur<v_count?v_cur+1:1;v_canPause=1;v_TIM=setTimeout("v_canPause=0;v_slide()",v_timeout);return};o.top=parseInt(o.top)-v_d;o2.top=parseInt(o2.top)-v_d;setTimeout("v_slide()",v_slideSpeed)};if(v_nS4||v_iE||v_oP||document.getElementById&&!v_kN&&!v_oP4){document.write('<style>a.vnewsticker{font-family:'+v_font+';font-size:'+v_fontSize2+';color:'+v_fontColor+';text-decoration:'+v_textDecoration+';font-weight:'+v_fontWeight+'}a.vnewsticker:hover{font-family:'+v_font+';font-size:'+v_fontSize2+';color:'+v_fontColorHover+';text-decoration:'+v_textDecorationHover+'}</style>');v_temp='<div '+(v_nS4?"name":"id")+'=v_container style="position:'+v_position+';top:'+v_top+'px;left:'+v_left+'px;width:'+v_width+'px;height:'+v_height+'px; background-color:'+v_bgColor+';layer-background-color:'+v_bgColor+';clip:rect(0,'+v_width+','+v_height+',0);overflow:hidden">';for(v_i=0;v_i<v_count;v_i++)v_temp+='<div '+(v_nS4?"name":"id")+'=v_'+(v_i+1)+' style="position:absolute;top:'+(v_height*v_d)+'px;left:'+v_paddingLeft+'px;width:'+(v_width-v_paddingLeft*2)+'px;height:'+(v_height-v_paddingTop*2)+'px;clip:rect(0,'+(v_width-v_paddingLeft*2)+','+(v_height-v_paddingTop*2)+',0);overflow:hidden'+(v_oP?";visibility:hidden":"")+'"><a href="'+v_content[v_i][0]+'" target="'+v_content[v_i][2]+'" class=vnewsticker'+(v_pauseOnMouseOver?" onmouseover=\'if(v_canPause&&v_count>1){clearTimeout(v_TIM);v_cl=1}\' onmouseout=\'if(v_canPause&&v_count>1&&v_cl)v_TIM=setTimeout(\"v_canPause=0;v_slide();v_cl=0\","+v_timeout+")\'":"")+'>'+v_content[v_i][1]+'</a></div>';v_temp+='</div>';document.write(v_temp);setTimeout("v_start()",1000);if(v_nS4)onresize=function(){location.reload()}}
</script>

pyro
04-02-2003, 10:34 AM
What the problem is is these two lines:

v_content=[ at the end of your first script, and ]; at the beginning of you next one.

jrthor2
04-02-2003, 10:37 AM
so how can I fix this so that in between the v_content=[ and ];, is the results of an external file??

pyro
04-02-2003, 10:51 AM
Useing PHP or SSI to include the content should work... Why do you need to include it as an external script?

jrthor2
04-02-2003, 10:58 AM
Well, my server doesn't support php (wish it did), so i tried this:

v_content=[
<!--#include file="/cgi-bin/newspro/News_Scroller.js"-->
];

I still get a syntax error. Is this correct for SSI? This script si on an asp page.

I need to include it form an external file because I want to generate my news headlines dynamicaly.

pyro
04-02-2003, 11:09 AM
Perhaps there is an error in the code in News_Scroller.js. Try including the contents of that file into the main script and see if it works.

jrthor2
04-02-2003, 11:17 AM
I took the contents of my News_Scroller.js script and pasted them in to my page script, and it works fine.?? I think it is something with the way it's being included. Is my syntax correct?

I changed it to this:

v_content=[
<!--include virtual="/cgi-bin/newspro/News_Scroller.js"-->
];

and now I get:

document.all[...].style is null or not an object

pyro
04-02-2003, 11:37 AM
Hmm... I just tried it and using includes like that seems quite finicky (both in PHP and SSI). I don't really know SSI, but if I were going to do this in PHP, I'd open the file, put the contents of the file into a variable and the write the variable. Perhaps that can be done in SSI?

BTW, your syntax on ths SSI include is a bit off. It should be

<!--#include virtual="/cgi-bin/newspro/News_Scroller.js"-->

jrthor2
04-02-2003, 11:40 AM
I doubt that can be done with SSI. What was wrong with my first atempt, where I had

v_content=[
</script>
<script src="/cgi-bin/newspro/News_Scroller.js">
</script>
<script language="JavaScript1.2" type="text/javascript">
];

Jona
04-02-2003, 12:05 PM
Are you writing the result to the page? If you're using document.write() to write the variable, you can use:

var variableName = ["<script src='cgi-bin/include/News_Header.js'>\n</script>"];

Just a comment. :p

jrthor2
04-02-2003, 12:12 PM
I'm very new to javascript, but I tried this:

var content = ["<script src='/cgi-bin/newspro/News_Scroller.txt'>\n</script"];
v_content=[
document.write(content);
];

and get the folowing error:

Active Server Pages error 'ASP 0138'

Nested Script Block

/index2.asp, line 247

A script block cannot be placed inside another script block.

I also just tried:

var v_content=["<script src='/cgi-bin/newspro/News_Scroller.txt'>\n</script"];

and I get ths same as above. the script is doing a document.write on this v_content variable.

Jona
04-02-2003, 12:28 PM
Actually, you have to escape it. Use this instead:

var content = ["<\script src='cgi-bin/include/file.js'\></\script>"];

That way it doesn't know that you're putting a <script> inside of a <script>. :)

jrthor2
04-02-2003, 12:36 PM
Hmm, now the word "undefined" scrolls 1 time in my scroll box. Any ideas about that?

Here's my code:

var v_content=["<\script src='/cgi-bin/newspro/News_Scroller.js'\><\/script>"];

jrthor2
04-02-2003, 02:01 PM
any other suggestions??

Jona
04-02-2003, 02:41 PM
Hmm... you're sure the News_Scroller code works? Hmmm.... a real toughie... Returning undefined would mean that there is something in the .js file that is returning undefined; not that the page itself is returning undefined...

Right, Pyro, my consultant? LOL :D j/k

jrthor2
04-02-2003, 02:54 PM
yes, if i take the code from News_Scroller.js and paste it into the v_content area, it works fine.

Jona
04-02-2003, 03:02 PM
That's very weird... It should work. I don't know what to tell you...

jrthor2
04-03-2003, 07:49 AM
anyone else have any ideas why this would happen, or a better way of including my external script in my javascript???

pyro
04-03-2003, 08:05 AM
Get on a server that supports PHP and use that...

jrthor2
04-03-2003, 08:19 AM
I wish it were that easy :-), but this is my churches website and it would take forever to get them to change their isp.

It ried to do some debugging, so I used an alert to show me what was in the v_content variable, and it showed me the actual script (<script src='/cgi-bin/newspro/News_Scroller.js'></script>), not the results fo the News_Scroller.js file, so I believe that is why I am getting the undefined message.

Any ideas how to get the actual data from that New_Scroller.js file??

thanks everyone!!

jrthor2
04-03-2003, 09:36 AM
Well, now I have this as my code:

var content = ["<\script src='/cgi-bin/newspro/News_Scroller.js'\><\/script>"];
alert(content);
v_content=[
document.write(content);
];

and the error I get now is

Expected "]"

jrthor2
04-03-2003, 09:55 AM
ok, well, now I am getting

Expected ';' at line 765, which I believe is the line bolded below. This is my whole code for this.

<script language="JavaScript1.2" type="text/javascript">
v_font='arial,helvetica,sans-serif';
v_fontSize='12px';
v_fontSizeNS4='11px';
v_fontWeight='normal';
v_fontColor='#330099';
v_textDecoration='none';
v_fontColorHover='#990033';// | won't work
v_textDecorationHover='underline';// | in Netscape4
v_bgColor='#d7d7ff';//set [='transparent'] for transparent
v_top=0;// |
v_left=0;// | defining
v_width=150;// | the box
v_height=60;// |
v_paddingTop=2;
v_paddingLeft=2;
v_position='relative';//absolute or relative
v_timeout=2500;//1000 = 1 second
v_slideSpeed=30;
v_slideDirection=0;//0=down-up;1=up-down
v_pauseOnMouseOver=true;
var content=["<\script src='/cgi-bin/newspro/News_Scroller.js'\><\/script>"]];
v_content=[
document.write(content);
];
// THE SERIOUS SCRIPT - PLEASE DO NOT TOUCH
v_ua=navigator.userAgent;v_nS4=document.layers?1:0;v_iE=document.all&&!window.innerWidth&&v_ua.indexOf("MSIE")!=-1?1:0;v_oP=v_ua.indexOf("Opera")!=-1&&document.clear?1:0;v_oP4=v_ua.indexOf("Opera")!=-1&&!document.clear;v_kN=v_ua.indexOf("Konqueror")!=-1&&parseFloat(v_ua.substring(v_ua.indexOf("Konqueror/")+10))<3.1?1:0;v_count=v_content.length;v_s1=1;v_cur=1;v_cl=0;v_d=v_slideDirection?-1:1;v_TIM=0;v_fontSize2=v_nS4&&navigator.platform.toLowerCase().indexOf("win")!=-1?v_fontSizeNS4:v_fontSize;v_canPause=0;function v_getOS(a){return v_iE?document.all[a].style:v_nS4?document.layers['v_container'].document.layers[a]:document.getElementById(a).style};function v_start(){var o=v_getOS('v_1');if(!o)return;if(v_iE||v_oP){if(o.pixelTop==v_paddingTop){v_canPause=1;if(v_count>1)v_TIM=setTimeout("v_canPause=0;v_slide()",v_timeout);return};o.pixelTop-=v_d;if(v_oP&&o.visibility.toLowerCase()!='visible')o.visibility='visible';setTimeout("v_start()",v_slideSpeed);return};if(parseInt(o.top)==v_paddingTop){v_canPause=1;if(v_count>1)v_TIM=setTimeout("v_canPause=0;v_slide()",v_timeout);return};o.top=parseInt(o.top)-v_d;setTimeout("v_start()",v_slideSpeed)};function v_slide(){var o=v_getOS('v_'+v_cur);var o2=v_getOS('v_'+(v_cur<v_count?v_cur+1:1));if(!o||!o2)return;if(v_iE||v_oP){if(o.pixelTop==v_paddingTop*2-v_height*v_d){if(v_oP)o.visibility='hidden';o.pixelTop=v_height*v_d;v_cur=v_cur<v_count?v_cur+1:1;v_canPause=1;v_TIM=setTimeout("v_canPause=0;v_slide()",v_timeout);return};o.pixelTop-=v_d;if(v_oP&&o2.visibility.toLowerCase()!='visible')o2.visibility='visible';o2.pixelTop-=v_d;setTimeout("v_slide()",v_slideSpeed);return};if(parseInt(o.top)==v_paddingTop*2-v_height*v_d){o.top=v_height*v_d;v_cur=v_cur<v_count?v_cur+1:1;v_canPause=1;v_TIM=setTimeout("v_canPause=0;v_slide()",v_timeout);return};o.top=parseInt(o.top)-v_d;o2.top=parseInt(o2.top)-v_d;setTimeout("v_slide()",v_slideSpeed)};if(v_nS4||v_iE||v_oP||document.getElementById&&!v_kN&&!v_oP4){document.write('<style>a.vnewsticker{font-family:'+v_font+';font-size:'+v_fontSize2+';color:'+v_fontColor+';text-decoration:'+v_textDecoration+';font-weight:'+v_fontWeight+'}a.vnewsticker:hover{font-family:'+v_font+';font-size:'+v_fontSize2+';color:'+v_fontColorHover+';text-decoration:'+v_textDecorationHover+'}</style>');v_temp='<div '+(v_nS4?"name":"id")+'=v_container style="position:'+v_position+';top:'+v_top+'px;left:'+v_left+'px;width:'+v_width+'px;height:'+v_height+'px; background-color:'+v_bgColor+';layer-background-color:'+v_bgColor+';clip:rect(0,'+v_width+','+v_height+',0);overflow:hidden">';for(v_i=0;v_i<v_count;v_i++)v_temp+='<div '+(v_nS4?"name":"id")+'=v_'+(v_i+1)+' style="position:absolute;top:'+(v_height*v_d)+'px;left:'+v_paddingLeft+'px;width:'+(v_width-v_paddingLeft*2)+'px;height:'+(v_height-v_paddingTop*2)+'px;clip:rect(0,'+(v_width-v_paddingLeft*2)+','+(v_height-v_paddingTop*2)+',0);overflow:hidden'+(v_oP?";visibility:hidden":"")+'"><a href="'+v_content[v_i][0]+'" target="'+v_content[v_i][2]+'" class=vnewsticker'+(v_pauseOnMouseOver?" onmouseover=\'if(v_canPause&&v_count>1){clearTimeout(v_TIM);v_cl=1}\' onmouseout=\'if(v_canPause&&v_count>1&&v_cl)v_TIM=setTimeout(\"v_canPause=0;v_slide();v_cl=0\","+v_timeout+")\'":"")+'>'+v_content[v_i][1]+'</a></div>';v_temp+='</div>';document.write(v_temp);setTimeout("v_start()",1000);if(v_nS4)onresize=function(){location.reload()}}
</script>

jrthor2
04-03-2003, 01:13 PM
does anyone have any suggestions for me to have scrolling news headlines from an external file???

Jona
04-03-2003, 02:25 PM
Errors like this is usually because there is a line before the error and the error report is invalid. In other words, the error probably actually occurs before that line specified. Try looking at the col (character number) and put a semi-colon where it is. Then see what happens. This won't fix the error, but it may help show you where the real error is occuring.

jrthor2
04-03-2003, 02:34 PM
Well, it says it's at Char 77. there aren't even 77 characters on that line????