Hi,
Display alert message if there is no validations after clicking of submit button
I have 2 textboxes for that i have required validations
currently my requirement is that after clicking of sumit button if everything is valid (no errors) then display success message else display relevant errors
could you please help me
<html>
<head>
<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();
}
}
function Save() {
}
</script>
</head>
<body>
@Html.TextBoxFor(a => a.Name, new { @id = "txtName" ,@onblur = "NameValidation()" })
<br />
@Html.TextBoxFor(a => a.Age, new { @id = "txtAge", @onblur = "AgeValidation()" })
<input type="button" value="Save" onclick="Save()" />
</body>
</html>