fractal5 Posted February 20, 2012 Share Posted February 20, 2012 So I'm trying to use a php form to query results from an sql database and generate a sortable table. For the table sorting I am using a javascript from here: The problem is that the javascript isn't working on the table generated from the php. But if I copy the output of the php into an html, the javascript sort works perfectly. This is a basic sample code I made to test the function: <?php echo "<html><head><title>new page</title>"; echo '<script src="sortable.js"> </script></head>'; echo '<body>'; echo "<table border='0' id='table' class='sortable'>"; echo "<thead>"; echo "<tr>"; echo "<th>Col1</th>"; echo "<th>Col2</th>"; echo "</tr></thead>"; echo "<tbody>"; echo "<tr>"; echo "<td>11</td>"; echo "<td>12</td>"; echo "</tr>"; echo "<tr>"; echo "<td>21</td>"; echo "<td>22</td>"; echo "</tr>"; echo "</tbody></table>"; echo "</body></html>"; ?> So I'm confused as to whether I'm doing something wrong or missing something, or if there's a reason why a javascript function won't work through php. I hope I have explained it clearly. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/257351-sortable-table-in-php-using-javascript/ Share on other sites More sharing options...
fractal5 Posted February 20, 2012 Author Share Posted February 20, 2012 This is the link to the javascript function, can't edit my OP: http://www.joostdevalk.nl/code/sortable-table/ Link to comment https://forums.phpfreaks.com/topic/257351-sortable-table-in-php-using-javascript/#findComment-1319090 Share on other sites More sharing options...
haku Posted February 21, 2012 Share Posted February 21, 2012 Javascript works on HTML. HTML is the output of a PHP script (usually - sometimes the output may be XML, JSON or something else). So the fact that the HTML was generated by a PHP script is irrelevant. Javascript can't tell how it was generated one way or another. So this says to me that you have some issue somewhere else in your code. Unfortunately, you didn't show us any other code, so I can't really say much more. Link to comment https://forums.phpfreaks.com/topic/257351-sortable-table-in-php-using-javascript/#findComment-1319475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.