Javascript Code For HTML5 Form Validation Not Working

Posted by MistUnleashed on Stack Overflow See other posts from Stack Overflow or by MistUnleashed
Published on 2014-05-30T21:06:57Z Indexed on 2014/05/30 21:25 UTC
Read the original article Hit count: 167

Filed under:
|
|
|

I'm new to JavaScript so I have no idea why this code does not work and validate my HTML5 Form like it should.

The JavaScript code which can be found below is supposed to check if the browser supports the required attribute and if it doesn't then it will validate the form and check for any empty spaces.

I got the code from this website.

In the body of the webpage containing my form I have this:

Below is the contactvalidate.js file:

$('#formTemplate').submit(function() {
if (!attributeSupported("required") || ($.browser.safari)) {
  $("#formTemplate [required]").each(function(index) {
  if (!$(this).val()) {
     alert("Please fill all required fields.");
     return false;
    }
   });
  }
 return false;
});

Do I need to change anything in this code or should it work?

As I've said I'm new to JavaScript so any help you guys could give me is greatly appreciated.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html5