0

I am using jquery validation engine in my project on the input fields.

The code structure is like this

<form>
  <input/>
  <input/>
</form>

and i validate the fields in keyUp.

Now how do i show the prompt only on the input that has a focus.

or in otherwise how do i validate a single input element that has focus inside a particular form as the validation engine is attached to the form..

I use JavaScript-MVC framework

Please do help me. Thanks in advance

1 Answers1

0

To validate a single input element that has focus inside a particular form on keyup try this

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.10.0/jquery.validate.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('form').validate({ onkeyup: false });

            $('form').bind('keyup', function () {
                $(':focus', this).valid();
            });

        });
    </script>
</head>
<body>
    <form>
    <input name="one" class="required number"/><br />
    <input name="two" class="required" /><br />
    <input type="submit" />
    </form>
</body>
</html>
politus
  • 5,996
  • 1
  • 33
  • 42