jquery - AJAX getting onChange to work -
i have set form user can comment entering name, email , comment.
i want run validation on input once user leaves #name field, can't work please help.
$(document).ready(function() { $('#name').on("change", function () { var name = $('input[name=name]'); if (name.val()=='') { //a regex check added later on check invalid caracters name.addclass('hightlight'); $('#name_error').show(); var error = true; } else { name.removeclass('hightlight'); $('#name_error').hide(); } if ($(error).length) { return false; } }); });
if want trigger on leave can use:
$('#name').blur(function() { //your code }
refer here: http://api.jquery.com/blur/
if want trigger on change than:
$('#name').change(function() { //your code }
refer here:http://api.jquery.com/change/
Comments
Post a Comment