Forum Moderators: open

Message Too Old, No Replies

weird problem with my little script

my javascript is generating an error, but I can't find it

         

gilahacker

8:14 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



Here it is:

<script type="text/javascript" language="javascript">
numads = (document.getElementById('myDiv').offsetTop) / 87;
if(numads>15) numads = 15;
for (i = 1; i < numads; i++)
{
if(typeof(rightmini[i]) == "undefined" ¦¦ rightmini[i] == "") {}
else
{
document.write('<div style="border:1px solid #ccc; margin-top:5px">' + rightmini[i] + '</div>');
}
}
</script>

And it's giving me this error:

Line: 213
Char: 1
Error: Syntax error
Code: 0
URL: the url's here but I can't post it!

"Line 213" in the code is the "</script>" (last line of the javascript)

Does my syntax look wrong anywhere?

Thanks in advance...

-Jason

kaled

9:49 am on Jun 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Between pascal, perl and js I get a bit mixed up, but perhaps you need to use div rather than / near the top.

Also, assuming numads is a local variable I would declare it
var numads = (blah) div 87;

Also note use of escape when writing closing tag thus :-
'<\/div>'

Also, I always place { on the end of a line rather than on a new line. Since js is a bit wierd in how it interprets semicolons and linebreaks this avoids any possible problems when following an if or an else.

Kaled.

RonPK

11:07 am on Jun 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In javascript I'd really go for the / ;)

Also, you may need to specify exactly what rightmini is.

gilahacker

12:28 am on Jun 17, 2005 (gmt 0)

10+ Year Member



Thanks guys,

moved the "{", declared numads with "var", and escaped the "/div".

rightmini is already defined as an array.

The weird part is that the code runs just fine, but I always get the error. It says "completed, but with errors" at the bottom of the browser...

The changes didn't seem to fix the problem... sometimes I get the error, sometimes I don't. Maybe it's internet explorer as firefox doesn't report any errors... I'm confused.

Thanks for your help though!

-Jason

rocknbil

1:13 am on Jun 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



gila "completed" means the page completed loading. It doesn't mean the script ran. As a developer you should go into Internet Options and tell IE to "warn you about every script error." This produces the pop-up warning instead of the quiet yellow triangle in the status bar.

Also you say it's already defined as an array, but your snippet starts out with the <script type . . . . tag. If it's defined as an array, it may be somewhere out of reach of your script, just as it's out of our view.

Pages execute top-down. Is it defined lower on the page? If it is, maybe rightmini doesn't exist when this is trying to execute. Move it up into this script or before it.

Dass all I got. :-)

gilahacker

11:46 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



@rocknbil

The array is created before this script, and this script is getting the array just fine because it's displaying the images from the array like it should.

The script is running like it should, the error just bugs me because this is for a business site and it looks bad to have an error showing in the status bar.

I'm thinking maybe it's an invalid character in the array or something. I'm going to check into that.

Thank you all for your suggestions so far!

-Jason