Jquery form validation not working as wished? Must be a better method?

Take a look at the following link, you will see I have a simple form with various fields that are required. I have put together a small script to validate entry before submission. Normally the random numbers are generated using php but for the example I have just added them manually.

The solution does seem to work but I would prefer as one input is completed the error would disappear. Currently this works for the standard inputs that just require some kind of entry but doesn't work when an input requires a valid email or sum. If a correct email is entered, but the verify question hasn't been entered the error still appears on the email field.

http://jsfiddle.net/marcsanders/xgZeV/

Any help much appreciated!

Answers


Try the following:

$('input.required').change(function() {
 $(this).parent('div').removeClass('error');
});

Updated jsFiddle here.

You may also consider using a html5 required attribute on elements that are required, rather than using javascript.


You can try adding "keydown" events on all mandatory inputs and remove the "error" class if at all it is there attached to the input.


Need Your Help

What are the programming languages for GPU

programming-languages gpu-programming

I read an article stating that GPU are the future of supercomputing. I would like to know what are the programming languages used for programming on GPU's

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.