我有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();"
,但这不起作用。
关于如何做到这一点的任何想法?
由于
答案 0 :(得分:0)
你可以这样做
function checkCheckBoxes() {
if (document.getElementsByName('confirm_agreement')[0].checked == false)
{
alert ('You must agree with the User Agreement Terms!');
return false;
}
}