Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: missing } after property list javascript

I am getting the below error.

Error

SyntaxError: missing } after property list

content:Al futaim, trading company<br />Building M, 36, Saih Shuaib 3 —

PHP code

$content=$servicecenter->getCompanyName()."<br />".$servicecenter->getAddress()."<br /><button type='button' value='Get Direction' class='button' onclick='closeInfoWindow(),calcRoute()' name='Get Direction'>Get Direction</button>"; 

Script

var infowindow = new google.maps.InfoWindow({
  content:<?php echo $content; ?>;
});
like image 234
Qaisar Satti Avatar asked Jul 31 '15 10:07

Qaisar Satti


People also ask

How do I fix SyntaxError missing after argument list?

The "SyntaxError: missing ) after argument list" occurs when we make a syntax error when calling a function, e.g. forget to separate its arguments with a comma. To solve the error make sure to correct any syntax errors in the arguments list of the function invocation. Copied!

What is missing after argument list?

The JavaScript exception "missing ) after argument list" occurs when there is an error with how a function is called. This might be a typo, a missing operator, or an unescaped string.


3 Answers

Use json_encode and delete the semicolon at end of line:

content: <?php echo json_encode($content); ?>  /* no ; here! */
like image 125
stdob-- Avatar answered Oct 12 '22 18:10

stdob--


Missing the quotes for content and no need of ; -

content: '<?php echo $content; ?>'

OR

content: <?php echo json_encode($content); ?>
like image 34
Sougata Bose Avatar answered Oct 12 '22 17:10

Sougata Bose


var infowindow = new google.maps.InfoWindow({
    content:<?php echo $content; ?>
});

You can't have a ; inside an object's declaration. If you want to separate properties, use ,.

Also, depending on what you want to echo there, you might need to add " around the php script.

like image 31
ralh Avatar answered Oct 12 '22 19:10

ralh