This is a snippet of the code that doesn’t work right. The closing </script> tag of the javascript for some reason isn’t recognized. The javascript is for a check all box that will check or uncheck all the checkboxes generated with each form. Each form is separate so I tried to slim down my code by including in the php loop. I had a version of this code working but it involved repeating the same javascript sample multiple times. If you can think of a way to do this differently, feel free to improve the code. At the moment though all I need to figure out why the closing tag of the javascript doesn’t work.
foreach($words as $word){
$i++;
$qry = "Select * FROM subs WHERE type = '$word'";
$q = mysql_query($qry) or die(mysql_error());
?>
<script type="text/javascript">
checked=false;
function checkedAll<?=$i?>(frm<?=$i?>)
{
var aa= document.getElementById('frm<?=$i?>');
if(checked == false) {
checked = true
}
else{
checked = false
}
for(var i =0; i < aa.elements.length; i++) {
aa.elements[i].checked = checked;
}
}
</script>
<?
echo '<form action="attacher.php" method="POST" id="frm'.$i.'" >';
echo '<input type="hidden" name="template" value="16">';
echo "<table border='1' cellpadding='10'>";
echo "<tr><td colspan=4 align='center'><strong>$word</strong></td> <td><input type='submit' value='Add to Template'></td></tr>";
echo "<tr><th><input type='checkbox' name='checkall".$i."' onclick='checkedAll".$i."'(frm".$i.");'></th><th colspan=3> CONTROLS</th> <th>$word's</th> </tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array($q)) {
// echo out the contents of each row into table
echo "<tr>";
echo '<td><input type="checkbox" name="word[]" value="'.$row['id'].'"</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
echo '<td><a href="attacher.php?template=16&word=' . $row['id'] . '">Attach</a></td>';
echo '<td>' . $row['word'] . '</td>';
echo "</tr>";
}
// close table>
echo "</table><br>";
echo '</form>';
}
?>
I have to mention that the convention of code you use (even if it is one – but I doubt it) isn’t very neat.
Why don’t you use just some safe variants?
How about something like this:
I really don’t recommend using shorttags anyway…