Jquery validate single key callback

callbackjqueryvalidation

I'm using jquery validate to validate my forms. I want to show a text field that is hidden when my This field is valid.

That is i want call a method when a text field is valid(on text field change, before clicking submit). Any ideas?

Best Answer

I'm not familiar with the validate plugin but hopefully it should slot in fairly easily here.

Attach a keyup event to your text field. The function you call should assess if the field is valid and show/hide the hidden text box accordingly.

$("theTextboxID").keyup(function() {
    var isValid = $(this).validate() //or whatever you need to validate
    if (isValid) {
        // I show by removing display:none
        $("hiddenTextBoxID").removeAttr("style");
    }
    else {
        // I hide by adding style=display:none
        $("hiddenTextBoxID").attr("style", "display:none");
    }
});