alwynmalan
alwynmalan

Reputation: 159

JavaScript errors, but can't see why

I'm running a very simple piece of code to increment a number in a stats file.

It works, but testing it in various IE versions I get the following errors. I got inconsistent performance from IE7 and 9 and I think this might be causing it.

I'm getting a syntax error on the following piece of script.

<script type="text/javascript">

 function updateLikeCount(){

     parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

}  <------------- *I get the error on this line*
</script>

And I'm also getting an error stating object expected in the following:

<body leftmargin="0" topmargin="0" onload="updateLikeCount();">

Upvotes: 3

Views: 72

Answers (5)

Matt Zeunert
Matt Zeunert

Reputation: 16561

Assuming the code in the question is server side code rather than the code that gets delivered to the client the answer depends on the code being included.

As others have pointed out, wrapping the include output in quotes might help:

parent.increment('likelinkspace14', '', ' Likes');


This line has a double comma:

parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

Without the html comment:

parent.increment('likelinkspace14', , ' Likes');

Upvotes: 2

nrsharma
nrsharma

Reputation: 2562

The problem is because of string parameter. You are trying to add a string parameter without quotes

try this

parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');

Upvotes: 1

slebetman
slebetman

Reputation: 113866

Fron inside a script tag <!--#include file="14stats.txt"--> is considered syntax error.

Well, not quite syntax error but it is not a comment. Inside a script tag it is interpreted as:

< // less than
! // boolean inversion
-- // decrement

Since there's nothing on the left of the < operator it generates an error (among many other things which may also generate errors).

Upvotes: 2

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

The problem is in the second parameter because is without '

Javascript parameter without ' is like a variable

try this:

<script type="text/javascript">
 function updateLikeCount(){
     parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');
}  
</script>

Upvotes: 2

Dipesh Parmar
Dipesh Parmar

Reputation: 27364

replace

parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

with

parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');

Upvotes: 3

Related Questions