Hello,
this is my code,
i dont know why it doest check all the box.
can somebody help me ?
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript"><!--
var formblock
;var forminputs;
function prepare()
{
formblock= document.getElementById('form_id');
forminputs = formblock.getElementsByTagName('input');
}
function select_all(name, value)
{
for (i = 0; i < forminputs.length; i++)
{
// regex here to check name attribute
var regex = new RegExp(name, "i");
if (regex.test(forminputs[i].getAttribute('name')))
{
if (value == '1')
{
forminputs[i].checked = true;
}
else {
forminputs[i].checked = false;
}
}
}
}
if (window.addEventListener)
{
window.addEventListener("load", prepare, false);
}
else if (window.attachEvent)
{
window.attachEvent("onload", prepare)
}
else if (document.getElementById)
{ window.onload = prepare;
}
//--></script>
</head>
<body>
<?php
require_once("db.php");
require_once("connection.php");
if (isset($_POST['submit']) && isset($_POST['actions']))
{
//echo "Post<br><pre>" . print_r($_POST, true) . "</pre>";
mysql_query("delete from test where id in(" . mysql_real_escape_string(implode(',', $_POST['actions'])) . ")") or die("Error when deleting records.<br>".mysql_error());
}
$getdata = mysql_query("select id,name FROM test");
echo"<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\"> <div>";
echo"<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">";
echo "<tr>
<td><input type=checkbox name=checkall onClick=\"checkAll(document.myform.list)\"></td>
<td>ID</td>
<td>NAME</td>
</tr>";
while ($row = mysql_fetch_array($getdata)){
extract($row);
echo "<tr>";
echo "<td><input type=checkbox name='actions[]' value='$id'></td>";
echo "<td>$id</td>";
echo "<td>$name</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
echo "<br>";
echo "<input type='button' name='CheckAll' value='Check All' onClick='select_all('actions', '1');'>";
?>
<br><br><br>
<input type="submit" name="submit" value="Remove checked item">
</form>
</body>
</html>
This post has been edited by vearns: 2 Feb, 2008 - 04:58 AM