i have 3 forms and a checkbox like this:
<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>
what i am trying to do is to validate the user clicking on that checkbox to submit any of those 3 forms.
if the user doesn't check the box then an alert comes up.
I know i need to use some java script, something like:
function checkCheckBoxes() {
if (document.frmTest.confirm_agreement.checked == false)
{
alert ('You must agree with the User Agreement Terms!');
return false;
}
}
then add onsubmit="return checkCheckBoxes();"
on the forms, but this doesn't work.
Any ideas on how this should be done?
Thanks
you can do it like this as
function checkCheckBoxes() {
if (document.getElementsByName('confirm_agreement')[0].checked == false)
{
alert ('You must agree with the User Agreement Terms!');
return false;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.