javascript - Required checkbox in html form, using Safari -


i created html form required checkbox, this:

<input type="checkbox" required name="terms"> accept terms. 

if you're using browsers explorer, chrome , firefox, form won't let submit unless check checkbox, if you're using safari can submit if don't check it.

what can solve issue?

safari not support attribute, need use javascript. add desired functionality explained here :

html:

<form action="" method="post" id="formid">     name: <input  required = "true"/>     <br />     <input type="submit" /> </form> 

javascript:

var form = document.getelementbyid('formid'); // form has have id: <form id="formid"> form.novalidate = true; form.addeventlistener('submit', function(event) { // listen form submitting         if (!event.target.checkvalidity()) {             event.preventdefault(); // dismiss default functionality             alert('please, fill form'); // error message         }     }, false); 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -