Hi Clofy,
Thanks for your valuable comments.
My validation code is
function addValidator(fieldName, fieldLabel) {
if (typeof (Page_Validators) == 'undefined') return;
$("#" + fieldName + "_label").parent().addClass("required");
var newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.controltovalidate = fieldName;
newValidator.errormessage = "<a href='#" + fieldName + "_label'>" + fieldLabel + " is a mandatory field.</a>";
newValidator.validationGroup = "";
newValidator.initialvalue = "";
newValidator.evaluationfunction = function () {
var value = $("#" + fieldName).val();
if (value === null || value === "") {
return false;
} else {
return true;
}
};
// Add the new validator to the page validators array:
Page_Validators.push(newValidator);
// Wire-up the click event handler of the validation summary link
$("a[href='#" + fieldName + "_label']").on("click", function () {
scrollToAndFocus(fieldName + '_label', fieldName);
});
}
Code to remove validation
//eg. removeValidator("customerid")
function removeValidator(fieldName) {
$.each(Page_Validators, function (index, validator) {
if (validator.id == "RequiredFieldValidator" + fieldName) {
Page_Validators.splice(index, 1);
}
});
$("#" + fieldName + "_label").parent().removeClass("required");
}
----------------------------------------------------------------
Below is code that that how I am calling it
$(document).ready(function () {
addValidator(fieldName1, fieldLabel1);
addValidator(fieldName2, fieldLabel2);
addValidator(fieldName3, fieldLabel3);
}
$("#Filed1.change(function () {
if (Page_Validators != null) {
Page_Validators.length = 0;
}
var selectedValue = $("#Filed1).val();
if (selectedValue != "66dff-4e04-ea11-a811-676723") { //non std, show and make mandatory
showSection("Section_1");
showSection("Section_2_0");
addValidator("fieldd2", "1.x");
addValidator("fieldd3", "1.3");
addValidator("fieldd4", "2.1");
addValidator("fieldd4", "xxx4");
addValidator("fieldd5", "xxx5");
}
else if (selectedValue == "e8712d864e-4e04-ea11-a811-66aasty") {
addValidator("fieldd2", "1.x");
addValidator("fieldd3", "1.3");
addValidator("fieldd4", "2.1");
addValidator("fieldd4", "xxx4");
addValidator("fieldd5", "xxx5");
}
}
Regards,
Windy