Uncaught SyntaxError: Unexpected end of input

I have this error Uncaught SyntaxError: Unexpected end of input but i don’t understand why.

<!DOCTYPE html>
<title>Esempio e-Cart</title>
    <script src="jsFunctions.js">
    for($i=0;$i < 10; $i++){
        echo "<div id=\"".$i."\"><br>\n";
        //on the next line is the error
        echo "<button type=\"button\" onclick=\"addToCart(\"".$i."\")\">Aggiungi al Carrello</button><br>\n";
        echo "</div><br>\n";

“Unexpected end of input” = “You forgot to close a control block somewhere.”

This code as displayed does not generate a PHP error.

I have never liked using a backslash to delimit variables and double quotes and prefer string concatenatation because it is easier to spot syntax errors:

    echo '<button type="button" onclick="addToCart(' 
         . $i .')">'
   		 .   'Aggiungi al Carrello'
   		 . '</button><br><br>' 
   		 . "\n";

1 Like

Thank you,it works.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.