jqueryvalidationinputerrorplacement

Placing Jquery validation error inside <input> box?


My problem:

After validating an input field, if validation isn't complete, i want to put the error-message into the orginal input field.

you can user insertAfter() and insertBefore() to, (duh!) insert after or before input field.

I couldn't find any solution to my problem on StackOverFlow.


Solution

  • SO HERE IS MY SOLUTION:

    THIS SCRIPT PLACES ERROR IN YOUR INPUT ELEMENT!

    <script>
      $(document).ready(function() {
            $("#theForm").validate({
    
                errorPlacement: function(error, element) { 
                    element.val(error[0].outerText);
                },
                debug: true
            });
        });
    

    Additionally you will need a script to remove the message when input is clicked.

    G'day!