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>
           ";
    ?>

Recommended Answers

All 2 Replies

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>
";
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.