I have a jQuery validation function for a form. Validation logic is pretty the same for all fields, what varies are field names. Can I pass html element's ID as an method parameter? I mean - I know I can, but how to place it after #?
function validateFieldName(){
var nameFieldLength = $("#nameField").val().length;
if(cgLength < 3 || cgLength > 15){
$("#nameFieldLab").html("error");
$("#nameFieldLab").show();
}else{
$("#nameFieldLab").hide();
}
}
What I wan't to have is single function, something like this:
function validateField(formField, errorLabel){
var fieldLength = $("#formField").val().length;
if(cgLength < 3 || cgLength > 15){
$("#errorLabel").html("error");
$("#errorLabel").show();
}else{
$("#errorLabel").hide();
}
}