Reputation: 72
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 sortleads()
is called on click, the JavaScript function is properly called. I attempted to escape the single quotes around ?sort=IDD
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'>
</th>";
display_string .= "</tr>";
$display_string .= "</thead>";
$display_string .= "<tbody>";
Javascript:
<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;
}
}
request.open("GET", "sortLeads.php"+query, true);
request.send(null);
}
</script>
Upvotes: 1
Views: 1489
Reputation: 4925
There is a syntax error in your PHP
change
$display_string .= "<th>ID <img src='img/down.png' alt = 'down arrow' onclick= 'sortLeads(\'?sort=IDD\')' height = '50px' width = '50px'>
</th>";display_string .= "</tr>";
to
$display_string .= "<th>ID <img src='img/down.png' alt='down arrow' onclick=\"sortLeads('?sort=IDD')\" height='50px' width='50px'></th>";
$display_string .= "</tr>";
Upvotes: 3