I have a jsfiddle here http://jsfiddle.net/cbyJD/74
The problem I am having is that it is not displaying the question number in the alert but instead displays NaN. Also even though all the text inputs have been filled in, it still displays an alert stating have I have an empty text input.
What am I doing incorrectly in my fiddle?
Jquery validation() function is here:
function validation() {
var alertValidation = "";
var _qid = "";
var _msg = "";
$("[class*='q']").each(function(i) {
var questions = parseInt($("[class*=q" + i + "_qnum]").text());
var marks = parseInt($("[class*=q" + i + "_ans_text]").text());
var txtinput = $("[class*=q" + i + "_mark]").val();
_qid = questions;
_msg = "You have errors on Question Number: " + _qid + "\n";
if (txtinput == '' || txtinput == null) {
alertValidation += "\n\u2022 You have not entered in a value for all the Indivdiaul Marks textbox\n";
}
if (alertValidation != "") {
return false; //Stop the each loop
}
});
if (alertValidation != "") {
alert(_msg + alertValidation);
return false;
}
return true;
}
the value here is $(“[class*=q” + i + “_qnum]”) empty, the web can’t find the class as you want, class=”q0_qnum” for when your “i” is 0