Hi there,
I'm wanting to use a javascript form validation that alerts the user if none of the available checkboxes have been checked. I've done some surfing to try to find a solution, but I think the recommendations aren't working becuase of the way I've created the checkboxes...
the following is the line of PHP code i use to display the checkbox in a table. The table is created from a loop because it obtains the information from a MySQL database (hence the use of echo):
echo '\t<TD><CENTER><INPUT TYPE="CHECKBOX" NAME="del[]" VALUE=".$row['id']."></TD>\n';
After submission of the form, PHP deletes the record out of the MySQL database, using $row['id'] as the identifier, which is why i've used del[] as the NAME of the input type:
if ($_POST['delete']) {
$del = $_POST['del'];
foreach ($del as $array) {
$delsql = "DELETE FROM spares WHERE id='$array';";
mysql_query($delsql);
echo "Record number ".$array." deleted!<BR>";
}
}
---- from here on is where I am stuck ----
The idea I had to validate the form was to use a function. The function would be called when the submit button is pressed like this (the table NAME is deletetable):
<INPUT TYPE="button" NAME="delete" onclick="validateCheckboxes()">
The function looks like this (which isnt working)
function validateCheckboxes() {
var formObj = document.deletetable;
if (formObj.del.length == "0") {
alert("Please select the records you wish to delete and try again!");
return false;
} else {
formObj.submit;
}
}
Any help would be greatly appreciated!!!!!