Search code examples
javascriptphpmysqlgoogle-visualizationtimeline

How to insert javascript into echo


Well i am trying to insert a javascript on php script

echo "['". $row['ac']. " ','<span onclick="alert(\'test\')">Click here!</span>',  new Date( ". $row['start']. " ),  new Date( ". $row['end']. " )], ";

but i am getting the below error:

( ! ) Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/tregoal/public_html/skai/schedule/index2.php on line 156

i am trying to archive a result as below in order to use it on google charts.

['DRIVER ',' 122 ', new Date( 2013,5,01,14,00,00 ), new Date( 2013,5,01,15,30,00 )],


Solution

  • You need to escape the double-quotes " that are used in the alert span

    echo "['". $row['ac']. " ','<span onclick=\"alert(\'test\')\">Click here!</span>',  new Date( ". $row['start']. " ),  new Date( ". $row['end']. " )], ";