繁体   English   中英

如何验证具有多种形式的复选框?

[英]how to validate a checkbox with multiple forms?

我有3种形式和类似这样的复选框:

<input type="checkbox" name="confirm_agreement" value=yes <?php if (isset($_POST["confirm_agreement2"])) {print "checked";}?>>I agree

<form action="https://www.paypal.com/webscr" method="post">
      <input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
       <input type="hidden" name="cmd" value="_xclick-subscriptions">
       <input type="hidden" name="business" value="paypal@exploretalent.com">
       <input type="hidden" name="no_shipping" value="1">
       <input type="hidden" name="no_note2" value="1">
       ...
       <input type="hidden" name="sra" value="1">
</form>

<form action="https://www.paypal.com/webscr" method="post">
      <input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
       <input type="hidden" name="cmd" value="_xclick-subscriptions">
       <input type="hidden" name="business" value="paypal@exploretalent.com">
       <input type="hidden" name="no_shipping" value="2">
       <input type="hidden" name="no_note2" value="2">
       ...
       <input type="hidden" name="sra" value="2">
</form>

<form action="https://www.paypal.com/webscr" method="post">
      <input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
       <input type="hidden" name="cmd" value="_xclick-subscriptions">
       <input type="hidden" name="business" value="paypal@exploretalent.com">
       <input type="hidden" name="no_shipping" value="2">
       <input type="hidden" name="no_note2" value="2">
       ...
       <input type="hidden" name="sra" value="2">
</form>

我想做的是验证用户单击该复选框以提交这3种表单中的任何一种。

如果用户未选中该框,则会出现警报。

我知道我需要使用一些Java脚本,例如:

function checkCheckBoxes() {
if (document.frmTest.confirm_agreement.checked == false)
{
    alert ('You must agree with the User Agreement Terms!');
    return false;
}
}

然后添加onsubmit="return checkCheckBoxes();" 在表格上,但这不起作用。

关于应该如何做的任何想法?

谢谢

你可以这样做



function checkCheckBoxes() {
if (document.getElementsByName('confirm_agreement')[0].checked == false)
{
    alert ('You must agree with the User Agreement Terms!');
    return false;
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM