我正在努力驗證一個複選框,似乎無法理解它出錯的地方。任何幫助都會很棒。因爲它是以數組形式從MySQL中提取的,所以我不確定這是不是我要出錯的地方。Javascript複選框驗證不在php中工作
<script language="JavaScript" type="text/javascript">
function checkform (form)
{
if(!form.check_box_delete[].checked) {
alert('Please check at least one of the options.');
return false;
}
return true;
}
</script>
這裏是人體代碼:
<form name="form" method="post" action="loan_checkedIn.php" onsubmit="return checkform(this);">
<?php
echo "<table border='1' align='center' width='900'>
<tr>
<th bgcolor='#00a3e0'><font face='Arial'>Select</font></th>
<th bgcolor='#00a3e0'><font face='Arial'>Customer</font></th>
<th bgcolor='#00a3e0'><font face='Arial'>Make</font></th>
<th bgcolor='#00a3e0'><font face='Arial'>Model</font></th>
</tr>";
$results = mysql_query("SELECT * FROM loan WHERE email='$email' AND status='Out'");
while($row1 = mysql_fetch_array($results))
{
echo "<tr>";
echo "<td align='center'><input type='checkbox' name='check_box_delete[]' value='" . $row1['id'] . "'></td>";
echo "<td align='center'><font face='Arial'>" . $row1['customer'] . "</font></td>";
echo "<td align='center'><font face='Arial'>" . $row1['make'] . "</font></td>";
echo "<td align='center'><font face='Arial'>" . $row1['model'] . "</font></td>";
echo "</tr>";
}
echo "</table>";
?>
<p align="center"><input type="submit" style="background-color:#00A3E0; color:#FFFFFF;" name="submit" value="Return Equipment"></p>
</form>
第一個問題,你得到的複選框列表? – Ravi
是的,它使用複選框在多行的一側從MySQL中提取所有細節,如果選中,系統工作正常,但如果沒有檢查,則說實際上沒有檢查完成。 – Coops
您應該查看開發人員工具控制檯,您將看到語法錯誤:'form.check_box_delete []'無效js –