我有两项协议,用户在继续购物车之前必须选中两个不同的框(每个协议1个)来“同意”。如果未选中任何框,则两个警报都会通知它们“同意”,然后每次继续设置为1,然后分别继续。但是,如果同时选中了“提交按钮”,则不会继续提交。如何获得以下服务?

两者都未选中?警报1

#1未选中?警报2

#2未选中?警报3

请帮忙!

<script language="Javascript">
function check_agree (form) {
if (form.agree.checked) {
}
else { alert('You must agree to the application agreement terms before continuing.'); }
}
form.submitButton.disabled = true;
function check_agree_2 (form) {
if (form.agree_2.checked) {
}
else { alert('You must agree to both!'); }
}
form.submit()
</script>


html

<form action='http://webisite.com' method='post' onSubmit="return false;">
<p>
 <span style="text-align: center">
 <input type ="checkbox" name="agree" value="anything">

 <b>I Agree To And Understand The Charges That Will Be Processed To My Credit Card</b></span></p>
<p>&nbsp;</p>
<input type ="checkbox" name="agree_2" value="anything">

 <b>I Have Read And Agree To The Member Agreement/Terms And Conditions </b>
 <p>&nbsp;</p>
 <span style="text-align: center">
 <input type="submit" name="submitButton" onClick="check_agree(this.form);check_agree_2(this.form)" value="Continue To Shopping Cart">

</form>

最佳答案

替换check_agree,删除check_agree_2,然后更改“提交”按钮。

function check_agree(form) {
if (form.agree.checked && form.agree_2.checked) {
  return true;
} else if(!form.agree.checked) {
  alert('You must agree to the application agreement terms before continuing.');
} else if(!form.agree_2.checked) {
  alert('You must allow us to charge your credit card.');
}
return false;
}


html

<input type="submit" name="submitButton" onClick="check_agree(this.form)" value="Continue To Shopping Cart">

10-04 16:07