Start New Discussion within our Web Development Community

getting a error at $item_id_g'. its bc of the quotes

<?php
    echo"
         <button type='submit' onmousedown='func('$item_id_g');'>test</button>
       ";
?>

i also tried this but didnt work

<?php
        echo"
             <button type='submit' onmousedown="func('$item_id_g');">test</button>
           ";
    ?>

getting a error

Which one? Technically it is correct PHP syntax (apart from the missing space between echo and the double quote perhaps), but not valid HTML/Javascript syntax.

Try it this way (escaping double quotes for javascript arguments):

<?php
echo"
<button type='submit' onmousedown='func(\"$item_id_g\");'>test</button>
";
?>

or this way (escaping double quotes for html attributes):

<?php
echo"
<button type=\"submit\" onmousedown=\"func('$item_id_g');\">test</button>
";
?>
This article has been dead for over six months. Start a new discussion instead.