kilogram kilogram - 1 year ago 75
jQuery Question

jQuery form validation with input color

I want to validate empty input field with jQuery, just like on this website

I like the effect when you submit the form on this website, the input is becoming red for a moment and gradually getting its initial color. You can watch this yourself

Here is video of this validation

Answer Source

Try something like this:

//check if input is empty    
          if($(this).val() == 0 || $(this).val() == '') {
          else {

//this function lights field which have class '.empty_field'
function lightEmpty(){
                   $(this).css('border','2px solid #d8512d');
                  $(this).css('border','1px solid #cdcdcd');

//this triggers lightEmpty()
if (emptyInputs.length != 0)

It's just changing border of inputs with specific color for time which you can write in setTimeout function. I think you can figure out where to use this code

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download