-4

I am a beginner in PHP, I just need a little bit php in my project.

I want to echo something in a script and it doesn't work. Why?

<div id="entree">
        <label>Mot de passe : </label><br><br>
        <input type="text" placeholder="Inserer Mot de passe" id="motdepasse" onKeyPress="if(event.keyCode == 13) mdp();"/>
            <br><br>
            <input type="button" onclick="mdp()" value="C'est parti!">
</div>

and my script :

function mdp()
{
   alert("ok");
   <?php echo "coucou";?>
}
Pradeep
  • 9,667
  • 13
  • 27
  • 34
Paul Tanné
  • 79
  • 10

2 Answers2

0

it should be like this way :

function mdp()
{
  var str = "<?php echo 'coucou';?>";
  alert(str);
}
Pradeep
  • 9,667
  • 13
  • 27
  • 34
0

There are few corrections here:

<?php echo "coucou";?> /* missed at the end `;?` */

For JS multiple statements without using ; will result in syntax error, try this

alert(<?=var_export("coucou",true)?>);