Question

I am Trying to escape these darn quotes and stuff in JS. I'm trying to use json_encode. My head hurts from looking at quotes, help???

  $list = '';

    // some loop here

   $message = 'centeredPopup(this.href,"myWindow","500","300","yes")';
   $jscode = 'json_encode('.$message.');return false';
   $list .= '<p> 
        <a href="http://www.example.com/something.php?id=' . $id . '" onclick="' 
              .htmlspecialchars($jscode) . '" >' . $name . '</a></p><br>';

Was it helpful?

Solution

If you want to call json_encode there, you need to do this.

$jscode = json_encode($message).';return false';

You don't even need json_encode for this. You can put this there:

$message = 'centeredPopup(this.href,"myWindow","500","300","yes")';
$jscode = $message.';return false';
$list .= '<p> <a href="http://www.example.com/something.php?id=' . $id . '" onclick="' .htmlspecialchars($jscode) . '" >' . $name . '</a></p><br>';

OTHER TIPS

Try:

$message = 'centeredPopup(this.href,"myWindow","500","300","yes")';
$jscode = json_encode($message);

Otherwise everything else should be OK.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top