Answer the question
In order to leave comments, you need to log in
How to do form validation in Safari?
I ran into trouble, no matter what kind of validation I use, the forms leave empty from the Safari browser! From other browsers everything is ok! Does anyone know an effective way to deal with safari? Here's an example that should actually work! Thanks in advance for your help!
var form = document.getElementById('formID'); // form has to have ID: <form id="formID">
form.noValidate = true;
form.addEventListener('submit', function(event) { // listen for form submitting
if (!event.target.checkValidity()) {
event.preventDefault(); // dismiss the default functionality
alert('Please, fill the form'); // error message
}
}, false);
<form action="" method="POST" id="formID">
Your name: <input required = "true"/>
<br />
<input type="submit" />
</form>
Answer the question
In order to leave comments, you need to log in
Make sure the input has a name.
Check if safari's event.target actually returns a link to the form (or try this).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question