CopyPastor

Detecting plagiarism made easy.

Score: 1.8567395083557758; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2018-05-16
by Suraj Libi

Original Post

Original - Posted on 2011-09-26
by robertc



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You can't trigger the native validation UI, but you can easily take advantage of the validation API on arbitrary input elements:
$('input').blur(function(event) { event.target.checkValidity(); }).bind('invalid', function(event) { setTimeout(function() { $(event.target).focus();}, 50); });
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
$('input').blur(function(event) { event.target.checkValidity(); }).bind('invalid', function(event) { setTimeout(function() { $(event.target).focus();}, 50); });
<!-- language: lang-css -->
label{ display: block; }
<!-- language: lang-html -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <label>URL <input id ="theurl" type="url"> </label><br> <label>Email <input id ="theemail" type="email"> </label><br> <button> Submit</button> </form>
<!-- end snippet -->

You can't trigger the native validation UI, but you can easily take advantage of the validation API on arbitrary input elements:
$('input').blur(function(event) { event.target.checkValidity(); }).bind('invalid', function(event) { setTimeout(function() { $(event.target).focus();}, 50); });
The first event fires `checkValidity` on every input element as soon as it loses focus, if the element is `invalid` then the corresponding event will be fired and trapped by the second event handler. This one sets the focus back to the element, but that could be quite annoying, I assume you have a better solution for notifying about the errors. [Here's a working example of my code above][1].

[1]: http://jsfiddle.net/robertc/4Hk9G/

        
Present in both answers; Present only in the new answer; Present only in the old answer;