Tidbit # 2: How to make users Agree to Terms using Javascript on your forms

I discovered a quick snippet on how to make users agree to your Terms and Conditions before allowing them to submit your forms using a simple javascript. I modified the original code I found to make it simpler, but to be fair I found the code at this site.

Javascript Code

First things first, you need a form that is submitting to somewhere, and a checkbox. The Javascript will then check that the form field is checked, if it is not checked, an alert pops up reminding the user to agree to the Terms and Conditions. Here is the javascript:

Form Code

Now that you have the javascript you need to point your form to the right place by adding the following code inside your form tag:

onSubmit="return agreeToTerms(this)"

To finish make it all work now you need to create a checkbox field and name it “agree_to_terms” without the quotes and it can’t hurt to give it an id as well like I have done below:

Additional Links:

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*