function validateForm()
{
var x=document.forms["myForm"]["email"].value;
if (x==null || x=="")
{
alert("Email must be filled out");
return false;
}
var a=document.forms["myForm"]["password"].value;
if (a==null || a=="")
{
alert("Password must be filled out");
return false;
}
var b=document.forms["myForm"]["name"].value;
if (b==null || b=="")
{
alert("Name must be filled out");
return false;
}
var c=document.forms["myForm"]["phone"].value;
if (c==null || c=="")
{
alert("phone must be filled out");
return false;
}
var d=document.forms["myForm"]["month"].value;
if (d==null || d=="")
{
alert("month must be filled out");
return false;
}
var e=document.forms["myForm"]["day"].value;
if (e==null || e=="")
{
alert("day must be filled out");
return false;
}
var f=document.forms["myForm"]["year"].value;
if (f==null || f=="")
{
alert("year must be filled out");
return false;
}
var g=document.forms["myForm"]["year"].value;
if (g==null || g=="")
{
alert("year must be filled out");
return false;
}
var h=document.forms["myForm"]["add1"].value;
if (h==null || h=="")
{
alert("Address must be filled out");
return false;
}
var i=document.forms["myForm"]["city"].value;
if (i==null || i=="")
{
alert("city must be filled out");
return false;
}
var j=document.forms["myForm"]["pcode"].value;
if (j==null || j=="")
{
alert("post code must be filled out");
return false;
}
if(!this.form.checkbox.checked)
{
alert('You must agree to the terms First.');
return false
}
if(!this.form.agree.checked)
{
alert('You must agree to the terms Secend.');
return true;
}
if(!this.form.under.checked)
{
alert('You must agree to the terms Third.');
return true;
}
}
表單驗證所有驗證工作,但複選框vaidation不工作
<form action="register.php" method="post" id="signupfrm" name="myForm" onsubmit="return validateForm()" >
<input type="checkbox" name="agree" id="agree"/style="margin-left:65px;">
<input type="checkbox" name="under" id="under" value="1"/style="margin-left:65px;">
<input type="checkbox" name="checkbox" id="dec" value="1"/style="margin-left:65px;">
<input type="submit" name="submit" value="submit" /style="margin-left:500px; width:120px; height:35px;" />
</form>
<形式行動= 「register.php」 方法= 「郵報」 ID = 「signupfrm」 NAME = 「myForm會」 的onsubmit = 「return validateForm()」> \t – user3060459
請編輯您的代碼以使其具有4個空格的縮進,然後堆棧可以正確顯示它。 – farvilain