pass variable through onclick()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • magy
    New Member
    • Oct 2012
    • 1

    pass variable through onclick()

    Code:
    <script language="javascript" >
    need this code to work please help i'm bignner
    
    function showmsg(arg)
    {
    	alert(arg);
    }
    </script> <?php 
    $msg="hello";
    echo '<img src="http://bytes.com/img/icons/ico_rej.gif" alt=""  style="cursor:pointer" onclick="showmsg($msg)" />';
    
    ?>
    Last edited by Rabbit; Oct 2 '12, 04:27 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    You need to surround the value that you pass into the javascript in quotes. Otherwise it won't recognize it as a string.

    Comment

    Working...