Forum Moderators: open
<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
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.
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
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. :-)
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