manpozi manpozi - 1 year ago 121
PHP Question

Invalid escape in identifier php

I have the below PHP code to generate a table that has a click-able image embedded in one of the columns. I know that the function works because if just

is called on click, the JavaScript function is properly called. I attempted to escape the single quotes around
but I get the following error
SyntaxError: Invalid escape in identifier: '\'
in my JavaScript console. I've also tried double backslashing to escape the backslashes but that gives a similar error. How should I properly escape the single quotes? I've also included all relevant code.

Relevant PHP excerpt:

$display_string .= "<th>ID <img src='img/down.png' alt='down arrow'
onclick= 'sortLeads(\'?sort=IDD\')' height='50px' width='50px'> </th>";

Full PHP:

$display_string = "<table class='table table-bordered table-hover scroller'>";
$display_string .= "<thead class='thead-inverse'>";
$display_string .= "<tr>";
$display_string .= "<th>ID <img src='img/down.png' alt='down arrow' onclick= 'sortLeads(\'?sort=IDD\')' height='50px' width='50px'>
display_string .= "</tr>";
$display_string .= "</thead>";
$display_string .= "<tbody>";


<script language="javascript" type = "text/javascript">
function sortLeads(query)
var request = new XMLHttpRequest();
request.onreadystatechange = function()
if (request.readyState == 4)
var results = document.getElementById('sortLeads');
results.innerHTML = request.responseText;
}"GET", "sortLeads.php"+query, true);

Answer Source

There is a syntax error in your PHP


$display_string .= "<th>ID <img src='img/down.png' alt = 'down arrow' onclick= 'sortLeads(\'?sort=IDD\')' height = '50px' width = '50px'>
</th>";display_string .= "</tr>";


$display_string .= "<th>ID <img src='img/down.png' alt='down arrow' onclick=\"sortLeads('?sort=IDD')\" height='50px' width='50px'></th>";
$display_string .= "</tr>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download