我有一个包含复选框的表单:
<form action="tienda3.php">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email to confirm the order">
</div>
<div class="form-group">
<div class="checkbox">
<label><input type="checkbox" id="TOS" value="This"> I certify that I am of legal age and I have read and agree to the
<a href="../terms.php" target="_blank">Terms of use</a> and
<a href="../privacy.php" target="_blank"> Privacy Policy </a>of Sdocks LLC</label>
</div>
</div>
<button type="submit" onclick="validate()" class="btn btn-primary">Submit</button>
</form>
我需要验证用户是否选中复选框以将表单发布到 tienda3.php。
我使用此脚本来验证用户是否已选中该复选框:
<script type=text/javascript>
function validate(){
if (document.getElementById('TOS').checked){
alert("checked") ;
}else{
alert("You didn't check it! Let me check it for you.");
return true;
}
}
</script>
如果选中该复选框,则表单将发布到 tienda3.php,否则必须显示警报,通知用户必须选中该复选框才能继续该过程。
就我而言,表单始终发布到 tienda3.php。该脚本检测复选框是否被选中,但在这两种情况下,表单始终打开文件 tienda3.php
慕村9548890
绝地无双