Hi,
I have 2 textboxes
currently my requirement is that if i am going to click another textbox it was clearing first textbox validation message
ex: initially i have not entered by value at that time it was displaying error
at that time validation of name field is clearing i don't want to clear as per as my requirement
once i enter value on age it was clearing name validation
my requirement is that i need to clear only particulat field if enter value
@model kendoreport.Models.Category
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function NameValidation() {
var focusSet = false;
if (!$('#txtName').val()) {
if ($("#txtName").parent().next(".validation").length == 0) {
$("#txtName").parent().after("<div class='validation' style='color:red;margin-bottom: 20px;'>Name is Required</div>");
}
e.preventDefault();
$('#txtName').focus();
focusSet = true;
} else {
$("#txtName").parent().next(".validation").remove();
}
}
function AgeValidation() {
var focusSet = false;
if (!$('#txtAge').val()) {
if ($("#txtAge").parent().next(".validation").length == 0) {
$("#txtAge").parent().after("<div class='validation' style='color:red;margin-bottom: 20px;'>Age is Required</div>");
}
e.preventDefault();
$('#txtAge').focus();
focusSet = true;
} else {
$("#txtAge").parent().next(".validation").remove();
}
}
</script>
</head>
<body>
@Html.TextBoxFor(a => a.Name, new { @id = "txtName" , @onblur = "NameValidation()" })
<br />
@Html.TextBoxFor(a => a.Age, new { @id = "txtAge" , @onblur = "AgeValidation()" })
</body>
</html>