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. Quote Link to comment 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/ Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.