By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,253 Members | 1,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

missing (semi-colon); before statement error

100+
P: 110
I'm getting a "missing ; before statement" error in javacript

I'm surprised i wasn't able to find anything about this on this site.
I am not sure why I'm getting this error, everything looks fine to me.

I thought it might be because of special characters in the variable field, but "\"ing them out didn't fix the issue.

I am building the javascript page via php. The offending output line is the first line
(I've included a few more lines incase it is a following line that is actually causing the error.

Expand|Select|Wrap|Line Numbers
  1. var searchStr = 539103&less%5B%5D=19224&less%5B%5D=512470&less%5B%5D=355349;
  2. seed = 539103;
  3. var num = 1;
  4. var start = 1;
  5. var numResults = 8;
  6.  
  7.  
the start of the php page which creates this string is

Expand|Select|Wrap|Line Numbers
  1. include '../includes/dbconnect.php';
  2. Header("content-type: application/x-javascript");
  3.  
  4.  
  5.  
  6.  
  7. $seed=  $_GET["seed"];
  8. $seed2 = $seed;
  9. $start= $_GET["start"];
  10. $results = $_GET['results'];
  11. $num = @$_GET['num'];
  12.  
  13. $query = "SELECT DISTINCT(sid), rate FROM votes WHERE start = '$seed' LIMIT 0,3";
  14. $result = mysql_query($query);
  15.  
  16. while ($row=mysql_fetch_array($result)){
  17.     $sid = $row['sid'];
  18.     $rate = $row['rate'];
  19.  
  20.     if($rate == 50){
  21.     $seed2 = "$seed2&less%5B%5D=$sid";
  22.     } if($rate == 25) {
  23.     $seed2 = "$seed2&more%5B%5D=$sid";
  24.     }
  25. }
  26.  
  27. echo "var searchStr = $seed2;\n";
  28. echo "seed = $seed;\n";
  29. if ($num != ''){
  30. echo "var num = $num;\n";
  31. } else {
  32. echo "var num = 0;\n";
  33. }
  34. echo "var start = $start;\n";
  35.  
  36. echo "var numResults = $results;\n";
  37. ?>
  38.  
  39.  
  40. function getSearchStrVote(sid, rate) {
  41.     var searchStrNew = searchStr;
  42.     if (rate == '50'){
  43.     searchStrNew = searchStrNew+"&more%5B%5D="+sid;
  44.     }
  45.     if (rate == '25') {
  46.     searchStrNew = searchStrNew+"&less%5B%5D="+sid;
  47.     carousel.scrollNext();
  48.     }    
  49.     searchStr = searchStrNew;
  50. }
  51.  
platform is winxp - firefox & ie 6&7. I haven't tried on mac.
Nov 12 '07 #1
Share this Question
Share on Google+
3 Replies


100+
P: 428
var searchStr = 539103&less%5B%5D=19224&less%5B%5D=512470&less%5B% 5D=355349

The javascript interpreter expected to find the end of a line in that expression-
If this is a string, wrap it in single or double quotes.
Nov 12 '07 #2

100+
P: 110
I figured it was something simple like that, but i still have no idea why I would put this var in quotes when I don't quote the rest of them.

Anyway, thanks for the help. that's awesome.
Nov 12 '07 #3

gits
Expert Mod 5K+
P: 5,390
I figured it was something simple like that, but i still have no idea why I would put this var in quotes when I don't quote the rest of them.

Anyway, thanks for the help. that's awesome.
hi ...

the reason is that in case you don't enclose it in quotes the interpreter tries to identify it unsuccessful as a number ... due to the special chars in it ... or as a variable-name ... unsuccessful too ... due to the special chars too :) ... in case it is a string you have to use the quotes that literally creates a new string ...

kind regards
Nov 12 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.