I cannot figure out why this isn't working, it was working fine last week and now it isn't. I figured I must have mistakenly changed something, but after going over the whole thing, I couldn't find anything. So, I'm wondering now if my code wasn't very good in the first place. Here is the delete.js file:
function deleterecord(form)
{
var checkBox = document.edit.checkbox;
var lenBox = checkBox.length;
var foundBox = false;
while( lenBox--> 0 )
{
if( checkBox[lenBox].checked === true )
{
foundBox = true;
break;
}
}
if( !foundBox )
{
alert("Please select a record to delete");
return;
}
var r=confirm("Once deleted, these records are gone forever.\n\n Are you SURE you want to proceed? ");
if (r==true)
{
form.submit();
}
else
{
alert("Phew! That was close!\n\n No records were deleted.");
window.location.reload(true);
}
return;
}
...and here is the html form:
<form action="process_delete.php" method="post" id="edit" name="edit">
<table cellpadding="4px" cellspacing="2px" border="1">
<tr align="center">
<td>Aircraft Reg</td>
<td>Date Installed</td>
<td>Prefix</td>
<td>Part Number</td>
<td>Flight Control</td>
<td>Lat Position</td>
<td>Long Position</td>
<td>Vert Position</td>
<td>Location</td>
<td>Material</td>
<td>OEM/PMA</td>
<td>Select</td>
</tr>
$result = mysql_query("SELECT * FROM installed $filter ORDER BY aircraft_reg , part_number, date_installed ASC");
$pagerow = mysql_num_rows($result);
if ($pagerow > 0 )
{
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['aircraft_reg'] . "</td>";
echo "<td>" . $row['date_installed'] . "</td>";
echo "<td>" . $row['prefix'] . "</td>";
echo "<td>" . $row['part_number'] . "</td>";
echo "<td>" . $row['flight_control'] . "</td>";
echo "<td>" . $row['lat_position'] . "</td>";
echo "<td>" . $row['long_position'] . "</td>";
echo "<td>" . $row['vert_position'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['material'] . "</td>";
echo "<td>" . $row['oempma'] . "</td>";
echo "<td align=\"center\"><input type=\"checkbox\" selected=\"\" id=\"checkbox\" name=\"check_list[]\" value=\"" . $row['id'] . "\"></td>";
echo "</tr>";
}
echo "<tr align=\"center\">";
echo "<td colspan=\"12\"><input type=\"button\" value=\"Delete Selected\" style=\"width:150px; height:30px;\" onClick=\"deleterecord(form)\"></td>";
echo "</tr>";
}
else
{
echo "<tr><td align=\"center\" colspan=\"12\"><h2>No Records To Display</h2></td></tr>";
}
</table>
</form>
I have tried different variations of the document.edit.checkbox; such as document.getElementById["edit"].checkbox; or document.getElementById["checkbox"]; but I'm not able to get it working. Here is a jsfiddle if that helps, and I removed the php bits and entered some sample values instead.
As you can probably tell I'm very new to Javascript, but I'm trying my best and would really appreciate any guidance you could provide.