I have my PHP code like below and its work fine
<tr onclick="window.location='../info/<?php echo $ouid;?>';" >
Now I am loading more data on press load more button via ajax
so I am trying like this
$tableData.= '<tr onclick="window.location='.'"../info/'.$ouid.';">
<td>'.$date_rated.'</td>
<td><img src="../../global_assets/uploads/users/'.$image.'" width="35" alt="">
<span >'.$rated_row["full_name"].'</span>
</td>
<td>'.$cancelled_by_txt.'</td>
<td><i ></i>'.$str1.'</td>
</tr>';
But now tr html code looks like this
<tr onclick="window.location=" ..="" info="" zxp2ibhfnu;"="">
so its not correct code for window location, its need like this
<tr onclick="window.location='../info/RQ5KWBIY6M';" >
I am new in PHP and trying from half hour to make it working but not getting idea how I can do it, Let me know if anyone here can help me for do the same. Thanks!
CodePudding user response:
You will need to escape some single quotes for the single quotes used in the javascript in the onclick attribute.
$ouid = "asd0f8a08f0";
$date_rated = "12/03/2021";
$image = "north_pole.jpg";
$rated_row["full_name"] = "Mighty Mouse";
$cancelled_by_txt = "grinch";
$str1 = "Paper Plane";
$tableData = "";
$tableData.= '<tr onclick="window.location='.'\'../info/'.$ouid.';\'">
<td>'.$date_rated.'</td>
<td><img src="../../global_assets/uploads/users/'.$image.'" width="35" alt="">
<span >'.$rated_row["full_name"].'</span>
</td>
<td>'.$cancelled_by_txt.'</td>
<td><i ></i>'.$str1.'</td>
</tr>';
Output:
<tr onclick="window.location='../info/asd0f8a08f0;'">
<td>12/03/2021</td>
<td><img src="../../global_assets/uploads/users/north_pole.jpg" width="35" alt="">
<span >Mighty Mouse</span>
</td>
<td>grinch</td>
<td><i ></i>Paper Plane</td>