Javascript:两个“我同意条款复选框”在一页上
我有两个协议,用户必须通过选中两个不同的框(每个协议 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> </p>
<input type ="checkbox" name="agree_2" value="anything">
<b>I Have Read And Agree To The Member Agreement/Terms And Conditions </b>
<p> </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>
I have two agreements that a user must "agree" to by checking two different boxes (1 for each agreement) before continuing on to the shopping cart. If no boxes are checked, both alerts notify them to "agree" before continuing on 1 at a time, as well as each individually. However, the "submit button" wont submit and continue on when both are checked. How can I get the following to work?
Both unchecked? Alert 1
#1 unchecked? Alert 2
#2 unchecked? Alert 3
Please help!
<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> </p>
<input type ="checkbox" name="agree_2" value="anything">
<b>I Have Read And Agree To The Member Agreement/Terms And Conditions </b>
<p> </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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
替换check_agree,删除check_agree_2,并更改提交按钮。
html
Replace check_agree, remove check_agree_2, and change the submit button.
html
也许试试这个:
...用这个:
Perhaps try this:
...with this:
为什么您想
提醒
用户?我认为这不是一个好的经历。在我看来,您可以禁用提交按钮,直到选中所有复选框。
这是一个例子:
HTML:
JavaScript:
您可以在此处观看现场演示:http://jsfiddle.net/XZyjw/
Why do you like to
alert
the user? I don't think it's a good experience.In my opinion, you can just disable the submit button until all the checkboxes are checked.
Here is an example:
HTML:
JavaScript:
You can see a live demo here: http://jsfiddle.net/XZyjw/