I'm working on an MVC form and need to show the validation messages for the fields, when user moves to a next field.
But the validations are showing up on page load too. I tried focusout & blur.
HTML:
<input type="text" class="required" id="txtName"/>
<span class="validation" style="display:none;">This field is required</span>
JS:
$(document).ready(function(){
$(".validation").hide(); //this doesn't seem to work
$(".required").blur(function () {
ValidateEmptyString();
});
});
function ValidateEmptyString(){
alert(); //triggers on page load
.....
$(".validation").show();
}
Try this instead:
Use the e.preventDefault()