So I am confused on where to put things in my code to work right. I found a simple javascript tutorial to add a function so that i can hide and show my php tables. but when i put it all together i cant get it to work. It works fine displaying the table without the javascript added and adding the "<tr id="table"> line of code. I dont know if the javascript is in the wrong place or not.any help would be great.thanks
Code:
<?php <script type="text/javascript"> function displayRow(){ var row = document.getElementById("table"); if (row.style.display == '') row.style.display = 'none'; else row.style.display = ''; } </script> $term = $_POST['term']; if ($_POST){ $sql = mysql_query("select * from table where Name like '%$term%'"); echo "TABLE:"; echo "<table border='1'> <tr id="table"> <th>Name</th> </tr>"; while ($row = mysql_fetch_array($sql)){ echo"<tr>"; echo "<td>" .$row['Name']. "</td>"; echo "</tr>"; } echo "</table>"; "<p><button onclick="displayRow()" >Show sd</button></p>"; ?>
Comment