I'm doing some simple validations using jQuery to check if all textboxes are filled.
$(document).ready(function () {
$("#<%= btnInsertCountry.ClientID %>").click(function () {
var codeValue = $("#<%= txtCountryCode.ClientID %>").val();
var nameValue = $("#<%= txtCountryName.ClientID %>").val();
if (codeValue == "" || nameValue == "") {
if (codeValue == "") {
$("#divCodeValidation").show();
}
else {
$("#divCodeValidation").hide();
}
if (nameValue == "") {
$("#divNameValidation").show();
}
else {
$("#divNameValidation").hide();
}
return;
}
});
});
The divs have the property display: none
and contains the error message. This code works but I don't like it because I use an if
to check if the values are empty and inside I have an if
for each variable.
Is there a better way to do this validation?