【发布时间】:2012-02-11 02:46:17
【问题描述】:
如果用户没有选中任何复选框,我想提醒他们,然后返回表单 在他们至少选中一个复选框后,进入下一页 我该怎么做?
<input type="checkbox" name="pay[]" value="
<?php
echo $DateArr[$record_count].";";
echo $invoiceArr[$record_count].";";
echo $TotalArr[$record_count].";";
echo $amount_dueArr[$record_count];
?>
" onClick="checkTotal()"/>
<td ALIGN="right" ><input type="submit" name="submit" value="Continue" onMouseOver="CheckBoxStatus()"></td>
javascript:
function CheckBoxStatus()
{
var checkbox_status = document.getElementsByName("pay[]").value;
if (checkbox_status = ";;;")
{
alert("Please select at least one to proceed!");
return false;
}
else
{
alert("Continue!");
return true;
}
}
如果用户没有选中,至少一个复选框,提醒消息并返回表单
然后
<form name="payform" method="POST" action="payment.php" onSubmit=" CheckBoxStatus()">
如果用户没有选中任何复选框,我怎样才能留在表单中?
可能是这样的:
function CheckBoxStatus()
{
if (document.getElementsByName("pay[]").checked == true)
{
document.forms["payform"].submit();
return true;
}
else
{
alert("Please select at least one invoice to proceed!");
document.forms["payform"].reset();
return false;
}
}
我可以这样做吗: `
function CheckBoxStatus()
{
var status=$("pay[]").attr('checked');
if (status=true)
{
//if(document.getElementsByName("pay[]").checked) {
return true;
}
else {
alert("Please select at least one to proceed!");
return false;
}
}`
【问题讨论】:
-
复选框在 JS 中总是有一个值,就像你生成它的方式一样。您要检查复选框的
.checked属性,即真/假。 -
如果 checkbox.value = ";;;" =假?
-
没有。
if (checkbox.checked == false) { ... it's not checked ...}. -
if(document.getElementsByName("pay[]").checked == false) { return true; } else { alert("Please select at least one to proceed!"); return false;} -
getElementsByName 返回一个匹配节点的数组......你真的需要阅读 DOM 操作......
标签: php html forms function checkbox