Please help us help you and fill where relevant:
Your LimeSurvey version:
6.5.10+240603
Own server or LimeSurvey hosting: Both
Survey theme/template: fruity
==================
I created a script to apply to an array type question with 8 sub-questions. I entered it into the source in the HELP section of the question editor, but it does not work. As shown in the attached picture, the warning message appears the first time, but afterwards the 'submit' button does not work. I want the 'submit' button to function after displaying the warning message once, regardless of whether any changes are made. Thank you in advance.
<script type="text/javascript">
$(document).ready(function(){
// Array of question codes
var questions = ;
// Intercept form submit event
$('#limesurvey').submit(function(event){
var sameAnswer = true;
var firstAnswer = $('#javatbd' + questions[0] + ' .radio input:checked').val();
// Check if the same answer is selected for all questions
for(var i = 1; i < questions.length; i++) {
var currentAnswer = $('#javatbd' + questions
+ ' .radio input:checked').val();
if(currentAnswer !== firstAnswer) {
sameAnswer = false;
break;
}
}
// If the same answer is selected for all questions, display a warning message
if(sameAnswer) {
// Check for previous warning message in local storage
var warned = localStorage.getItem('warnedAboutSameAnswers');
if (warned) {
// If the warning message has already been seen, allow form submission
return true;
} else {
// If seeing the warning message for the first time, display the warning message and stop form submission
alert("You have selected the same answer for all questions. Please review your responses.");
localStorage.setItem('warnedAboutSameAnswers', 'true');
event.preventDefault(); // Stop form submission
}
}
});
});
</script>