Q:

Variable inside double qoutes in onclick function

Hi guys i have gone through many questions discussing about variable inside double qoutes.But i don't know why those are not workin for me..
My situation is this 
onclick="cBack(this.form,{$pageurl},{$token})"

I have this kind of code inside my page..when clicking the button it calls a function.but in my case it is not working.it shows a reference error in my console..
my callback function
function cBack(frm,pageurl,token)
  {

    pageurl=pageurl.trim(); 
    frm.method="post";
    frm.action=pageurl+'?gtoken='+token;
    frm.submit();  

}

Help me solving this..

A:

$pageurl and $token are strings and need quotes like this:
onclick="cBack(this.form,'{$pageurl}','{$token}')"

With plain PHP and no templating engine:
onclick='cBack(this.form,<?php echo json_encode($pageurl) ?>, <?php echo json_encode($token) ?>)'

Notice I switched to single quotes, because json_encode will use double quotes. This produces save (means encoded) JavaScript parameters regardless of the content of your variables.

