I have the following: A side-by-side question with four text entry questions, and 16 rows.
I need the following: Condition (1)Validation to check that the entries in the third column are only numbers, between 1 and 16. Condition (2) no number in the third column should appear twice. I have attached the code.
The problem: I get the error “The rank 1 is already assigned. Please enter a unique value for each factor”. every time I finish the question and hit the next button.
I use validationIndices for condition (1) and enteredValues for condition (2).
I have been stuck with this problem for a week. Any pointers are appreciated.
The code:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var textboxIndices = t3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63];
// Loop through the specified indices
for (var i = 0; i < textboxIndices.length; i++) {
var index = textboxIndicesai];
jQuery("#" + this.questionId + " input+type=text]:eq(" + index + ")").css("width", "350px");
}
});
Qualtrics.SurveyEngine.addOnReady(function() {
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#"+this.questionId+" tr.Headings").hide();
// Assuming 'this.questionId' refers to the third question in your side-by-side setup
var totalRows = 16 * 4; // Change this to the actual number of rows in your question
var validationIndices = o];
// Generate indices based on the pattern
for (var j = 2; j < totalRows; j += 4) {
validationIndices.push(j);
}
// Array to store entered values
var enteredValues = s];
// Input validation code for the specified textboxes
jQuery("#" + this.questionId + " inputttype=text]").on("change", function() {
var currentIndex = jQuery(this).index("inputrtype=text]");
if (validationIndices.includes(currentIndex)) {
var inputValue = jQuery(this).val();
if (inputValue !== "" && (isNaN(inputValue) || inputValue < 1 || inputValue > 16)) {
alert("Please enter a rank between 1 and 16");
jQuery(this).val("");
} else {
// Check for uniqueness
if (enteredValues.includes(inputValue)) {
alert(“The rank " + inputValue + " is already assigned. Please enter a unique value for each factor");
jQuery(this).val("");
} else {
enteredValues currentIndex] = inputValue;
}
}
}
});
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});