Quick validation

Discussion in 'JavaScript' started by dexpras, Nov 11, 2013.

  1. #1
    How could I validate forms even before pressing submit button using ajax ?. Error must appear just after entered the value in to the field.
    Eg:
    Capt.PNG
     
    dexpras, Nov 11, 2013 IP
  2. gandalf117

    gandalf117 Active Member

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    To validate without clicking the submit button you can use something like:

        var el = document.getElementById('inputFieldId');
    
        el.onblur = function() {
    
            var value_to_validate = el.value;
    
            //make an ajax request and send the value from the input field for validation
    
            //if the request returns an error attach the proper message to the proper place in the DOM
    
        }
    Code (markup):
    You can follow this tutorial on how to make ajax requests to validate a form:

    http://www.designchemical.com/blog/index.php/jquery/create-your-own-jquery-ajax-form-submit-with-validation/
     
    gandalf117, Nov 14, 2013 IP