Jquery each function promblem.
- by Cesar Lopez
I have the following function:
var emptyFields = false;
function checkNotEmpty(tblName, columns, className){
emptyFields = false;
$("."+className+"").each(function() {
if($.trim($(this).val()) === "" && $(this).is(":visible")){
emptyFields = true;
return false; // break out of the each-loop
}
});
if (emptyFields) {
alert("Please fill in current row before adding a new one.")
} else {
AddRow_OnButtonClick(tblName,columns);
}
}
Its checking that all elements in the table are not empty before adding a new row, and I only need to check that the last row of the table has at least an element which its not empty and not the whole table.
The className its applied to the table. Please notice, that the problem I have its checking the last row and only one element of the row has to have some text in it. (e.g. each row has 5 textboxes at least one textbox need to have some text inside in order to be able to add another row, otherwise, the alert comes up).
Any help would be apreciated.
Thanks