And so, onСlick does not work. This message pops up:

 Uncaught SyntaxError: Unexpected token } 

Here is the php code:

 <?php echo "<article onclick = 'document.getElementById('myform').submit()'> <h3> {$row['name']} </h3> <p class='creator'>Создатель: {$row['creator']}</p> </article>" 

Where is the mistake?

  • 2
    But what do you have - {$row['name']} , {$row['creator']} ? - rjhdby
  • @rjhdby, the author most likely presented in the question the code is inside a single PHP-string of double quotes (which, in fact, explains the lack of it when specifying tag arguments). Such inserts in a double quote string in PHP are interpreted as $row['name'] and $row['creator'] variables, respectively. - neluzhin

2 answers 2

It is necessary to replace the quotes inside the onclick attribute with double ones:

 <article onclick = 'document.getElementById("myform").submit()'> 

Or vice versa:

 <article onclick = "document.getElementById('myform').submit()"> 

    Thanks @terron for the tip, everything became clearer.

    In this case, you need to not only change the quotes, as suggested by @ Makim (although the problem is noted correctly), but also to screen them in this way.

     <?php echo "<article onclick = 'document.getElementById(\"myform\").submit()'> <h3> {$row['name']} </h3> <p class='creator'>Создатель: {$row['creator']}</p> </article>" 

    But it's better never to do that. It is necessary to separate HTML and PHP. Something like this

     ?> <article onclick = 'document.getElementById("myform").submit()'> <h3> <?php echo $row['name'];?> </h3> <p class='creator'>Создатель: <?php echo $row['creator']?></p> </article> <?php