Below is my validation function:
function validation() {
alertValidation= "";
// Note, this is just so it's declared...
$(".textAreaQuestion").each(function() {
if (!this.value || this.value.length < 5) {
alertValidation += "\nYou have not entered a valid Question\n";
}
if(alertValidation != ""){
return false;//Stop the each loop
}
});
$(".numberAnswerTxtRow").each(function() {
if (!this.value) {
alertValidation += "\nPlease Enter in the Number of Answers you Require for this question\n";
}
if(alertValidation != ""){
return false;//Stop the each loop
}
});
$(".txtWeightRow").each(function() {
if (!this.value) {
alertValidation += "\nPlease enter in a figure for Number of Marks for this Question\n";
}
if(alertValidation != ""){
return false;//Stop the each loop
}
});
What the code above does is that it displays an alert for each row if there are any errros in the row.
Example:
If in a table row the user has left .textAreaQuestion, .numberAnswerTxtRow and .textWeightRow all empty, then in the alert it will display all of the related messages in one alert like below:
You have not entered a valid Question
Please Enter in the Number of Answers you Require for this question
Please enter in a figure for Number of Marks for this Question
Now each table row has its own question number (table row number). So what I want to know is that how can I include the question number in the alert so that it states which rows the alert messages are refering to? If it was like the example above I want the alert to be displayed like below:
You have errors on question number: 1 // how do I display this line in the alert
You have not entered a valid Question
Please Enter in the Number of Answers you Require for this question
Please enter in a figure for Number of Marks for this Question
Below is the code on how the question number is added into each table row:
var qnum = 1;
function insertQuestion(form) {
var $tbody = $('#qandatbl > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
var $qid = $("<td class='qid'>" + qnum + "</td>");
$tr.append($qid);
$tbody.append($tr);
$(form).find('.numberOfQuestions').val(qnum);
++qnum;
$("#questionNum").text(qnum);
}
Thanks
Well since you added the class qid to the td containing the questionnumber you should be able to access it via
$('td.qid').html(). This gives you the innerhtml of the td with the class qid check here for more info.EDIT:
On second thought
$('td.qid').text()might be better.