“Agree on Terms”-checkbox change error message

Viewed 3097

I use this question "Agree on Terms"-checkbox code to add "Agree on Terms" on my PHP Wordpress Page but i need change error messagge if user not accept the checkbox.

Is possibile?

This is my code use

<form action="#" onsubmit="if(document.getElementById('agree').checked) { return true; } else { alert('Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy'); return false; }">
    <input type="checkbox" required name="checkbox" value="check" id="agree" /> I have read and agree to the Terms and Conditions and Privacy Policy
    <button type="submit" class="btn" name="reg_user">Register</button>
</form>
1 Answers

Just change this string in your code:

'Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy'

Make sure you don't use ' in your error msg itself - it defines the end of the string.

Edit:

if you remove required name="checkbox" it should work because if you do have the required name in your code the form itself will check if the checkbox is checked. This would lead to your js code not being executed. Also you should consider puting your js code into a seperate file.

Related