我有一个简单的HTML文件,其中book seat字段为数组,代码如下
<input type="checkbox" name="book[]" value="<?php echo $i; ?> /><?php echo $i; ?>
<input type="submit" value="BOOK" onclick = "checkIfSeatEmpty()" />
我用来验证字段book
是否为空的javascript是:
var x=document.forms["bkfrm"].getElementById("chkbx").value;
//alert(x); alerts 'undefined' !
// var x=document.forms["bkfrm"].getElementById("book").length;
alert(x);
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
return TRUE;
但上面的代码警告为undefined
!如何检查该字段是否为空?
答案 0 :(得分:0)
尝试以下
var x=document.forms["bkfrm"].getElementById("book").checked;
答案 1 :(得分:0)
你的html代码中没有像chkbx或book那样的id。使用下面的代码
Jquery
$( “输入[名称= '书']:检查”)VAL();
。