croz
03-10-2012, 06:32 PM
Hi everyone,
I'm using JS to validate a (terms and conditions) checkbox that is to be used in conjunction with an 'add to cart' button. The script I'm using is:
<script type="text/javascript">
function validate ( checkbox, radiobutton )
{ if (checkbox == false)
{ alert("You must agree to the Terms and Conditions before you can add to cart");}
else
{document.form.submit();}
}
</script>
An example of a form being used for the 'add to cart' and checkbox is as follows:
<form name="form" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="MC5XC8DG72UME">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="lc" value="GB">
<table><tr><td>
<input type="hidden" name="radioChecked" value="false">
</td></tr></table>
<a href="Javascript:validate(document.form.CheckBox.checked, document.form.radioChecked.value);">
<img src="http://i1134.photobucket.com/albums/m604/franktheoilman/frankbutton.jpg" border="0" alt="PayPal — The safer, easier way to pay online"><img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"></a><br>
<INPUT TYPE="CheckBox" NAME="CheckBox" VALUE="CheckBox"></form>
This works pretty well, but due to some restrictions of using paypal (that cannot be avoided) I could do with having more than one 'add to cart' button on the same page (to account for different product sizes).
As each 'add to cart' has a unique "hosted button id" I'm assuming each button has to be contained within its own form (with its own name/id and checkbox).
And as the code I have seems to be reliant on the form name in order to submit, the problem i'm have is how to add an additional form with its own id and have either id submit independently.
Any help with this would be greatly appreciated!
I'm using JS to validate a (terms and conditions) checkbox that is to be used in conjunction with an 'add to cart' button. The script I'm using is:
<script type="text/javascript">
function validate ( checkbox, radiobutton )
{ if (checkbox == false)
{ alert("You must agree to the Terms and Conditions before you can add to cart");}
else
{document.form.submit();}
}
</script>
An example of a form being used for the 'add to cart' and checkbox is as follows:
<form name="form" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="MC5XC8DG72UME">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="lc" value="GB">
<table><tr><td>
<input type="hidden" name="radioChecked" value="false">
</td></tr></table>
<a href="Javascript:validate(document.form.CheckBox.checked, document.form.radioChecked.value);">
<img src="http://i1134.photobucket.com/albums/m604/franktheoilman/frankbutton.jpg" border="0" alt="PayPal — The safer, easier way to pay online"><img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"></a><br>
<INPUT TYPE="CheckBox" NAME="CheckBox" VALUE="CheckBox"></form>
This works pretty well, but due to some restrictions of using paypal (that cannot be avoided) I could do with having more than one 'add to cart' button on the same page (to account for different product sizes).
As each 'add to cart' has a unique "hosted button id" I'm assuming each button has to be contained within its own form (with its own name/id and checkbox).
And as the code I have seems to be reliant on the form name in order to submit, the problem i'm have is how to add an additional form with its own id and have either id submit independently.
Any help with this would be greatly appreciated!