html - Required Attribute Not work in Safari Browser -


I tried the following code to create the required field to notify the required field but it does not work in the Safari browser Has been doing. Code:

  & lt; Form action = "" method = "post" & gt; & Lt; Input required / & gt; Your name: & lt; Br / & gt; & Lt; Input type = "submit" / & gt; & Lt; / Form & gt;   

Code in Firefox

Can you tell me the javascript code or any workspace? New in javascript

thanks

Safari does not support it Attribute, you have to use javascript. This page contains a hacked solution that should add the desired functionality:

  & lt; form action = "" method = "post" id = "form id" & gt; Your name: & lt; Input required = "true" /> & Lt; Br / & gt; & Lt; Input type = "submit" / & gt; & Lt; / Form & gt;   

Javascript:

  var form = document.getElementById ('formID'); // ID has the form: & lt; Form id = "formID" & gt; Form.noValidate = true; Form.addEventListener ('submit', function (event) {// Submit form for note if !! Event.target.checkValidity ()) {event.preventDefault (); // Dismiss default functionality warning (please, form '); // error message}}, wrong);   

You can change the warning with a less ugly warning, such as a DIV with an error message:

  document.getElementById ('errorMessageDiv' ) .style.display = 'block';   

and in HTML:

  & lt; div id = "errorMessageDiv" style = "display: block;" & Gt; Please, fill out the form. & Lt; / Div & gt;   

(style attribute content should be in CSS file)

The only drawback of this approach is that this is the exact input that can be filled It is necessary that it will require a loop in all the inputs in the form and check the value (and check for better, "required" attribute presence).

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -