Appendix JS_F_A5
Summary
Requirement: If an input error is detected, the field should be identified and the error described in text.
Details: Do not force the focus to remain in invalid fields.
Examples
Correct code
See the JS_F_A1-A3-A4 appendix.
Incorrect code
Refer to the JS_F_A5 live demo for a working example.
<form action="#"> <fieldset> <p> <label for="demo">Number field:</label> <input id="demo" name="demo" type="text" /> </p> </fieldset> </form>
var input = document.getElementById('demo'); input.addEventListener('blur', function(e) { if(input.value && !/^[\d]+$/.test(input.value)) { window.setTimeout(function() { input.focus(); }, 10); } }, false);