验证复选框-不检测它'选中
Validating Checkboxes - Not detecting it's checked
我一整天都在纠结这个问题。除了复选框之外,所有其他验证都可以正常工作。它似乎验证了它,但没有检测到什么时候检查。意思是,我选中一个方框,它仍然会让我输入联系时间,不管我选中哪个方框。请帮助! !
只是那个选择最佳时间联系你的那个出了问题。
下面是我的复选框:
<input id="best_contact_time" name="best_contact_time" value="Morning 7-12" class="inputCheckbox" type="checkbox">Morning (7-12)<br>
<input id="best_contact_time" name="best_contact_time" value="Afternoon 12-5" class="inputCheckbox" type="checkbox">Afternoon (12-5)<br>
<input id="best_contact_time" name="best_contact_time" value="Evening 5-9" class="inputCheckbox" type="checkbox">Evening (5-9)<br>
我的验证码:
function submitme() {
// Validate required fields
if (get_element('lastname').value == '') {
alert('Please enter your last name');
return false;
}
if (get_element('first_name').value == '') {
alert('Please enter your first name');
return false;
}
if (get_element('phone').value == '') {
alert('Please enter a phone number');
return false;
}
if (get_element('email').value == '') {
alert('Please enter an email address');
return false;
}
var ischecked = 0;
for (var i = 0; i < document.rental.best_contact_time.length; i++) {
var e = document.rental.best_contact_time;
if (e.checked == true)
{ ischecked = 1; }
}
if (ischecked == 0) {
alert('Please enter the best time to contact you');
return false;
}
if (get_element('approximate_start_date').value == '') {
alert('Please enter an approximate start date');
return false;
}
document.forms[0].submit();
return true;
}
由于您有多个具有相同名称的元素,因此document.rental.best_contact_time
将是NodeList而不是HTMLElementNode。
您需要循环遍历列表(将其视为数组)并依次检查每个列表
相关文章:
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- jQuery复选框未选中检测问题
- 类事件处理程序未检测是否选中复选框
- 动态 javascript,用于检测复选框是否被选中并禁用相应的输入字段
- 检测复选框是否在 Angular.js ng-change 事件中处于选中状态
- 用于检查和取消选中复选框列表控件检测的 Javascript
- 复选框选中全部无法检测数据
- 尝试检测网格视图的哪一行处于编辑模式,然后在选中复选框字段时调整文本框
- 如何检测此单选按钮是否已选中
- JQuery检测下拉值被选中,即使它's没有改变
- 在JavaScript中检测组合框选中的项目
- 验证复选框-不检测它'选中
- 我如何检测当一行被选中和非行被选中在jqgrid
- 检测元素外部的点击,检查复选框是否被选中,并触发点击
- 如何使用jQuery检测组中的单选按钮是否被选中
- 如何使用jquery检测选中的单词并更改输入字段的背景
- 有效检测选中复选框的数量
- 如何用jQuery检测某个单选按钮是否被选中
- Javascript:检测是否选中复选框不工作
- AngularJS:检测ngRepeat中哪个复选框被选中/未选中,并调用一个函数