- Posts: 88
- Thank you received: 33
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript"> $(document).ready(function() { //This script will change the background of a selected array answers td for single response arrays. //getting the question id's and counting how many sub questions are in the list var sgq = "{SGQ}"; var ansCode = "java"+sgq; var rowCount = $('.subquestions-list tbody tr').length; //console.log(ansCode); //cycling through the subquestions to see if they are answered, if so it will color the correct td for the answer. // Needed for page reload or answers will lose background color. for(var i = 0; i < rowCount; i++ ) { var iPlusOne = i + 1; var currentAnswer = ansCode + iPlusOne; var currentValue = document.getElementById(currentAnswer).value; var currentCell = "answer_cell_00"+currentValue; var currentRowCell = "#javatbd"+sgq+iPlusOne+" ."+currentCell; if(document.getElementById(currentAnswer).value != "" ) { //console.log(currentRowCell); $(currentRowCell).addClass("selected-answer"); } } //highlights the td for the clicked answer. Will also remove the highlight of the old one if the answer is changed. $(".subquestions-list td").click(function() { var currentTr = "#" + $(this).closest("tr").attr("id") + " td"; //console.log(currentTr); $(currentTr).removeClass("selected-answer"); $(this).addClass("selected-answer"); }); }); </script>
<script type="text/javascript"> $(document).ready(function() { //Checks if the question type matches the array type we want var qId = "{QID}"; var questionId = "#question"+qId; //console.log(questionId); if($(questionId).hasClass('array-flexible-row')) { //This script will change the background of a selected array answers td for single response arrays. //getting the question id's and counting how many sub questions are in the list var sgq = "{SGQ}"; var ansCode = "java"+sgq; var rowCount = $('.subquestions-list tbody tr').length; //console.log(ansCode); //cycling through the subquestions to see if they are answered, if so it will color the correct td for the answer. // Needed for page reload or answers will lose background color. for(var i = 0; i < rowCount; i++ ) { var iPlusOne = i + 1; var currentAnswer = ansCode + iPlusOne; var currentValue = document.getElementById(currentAnswer).value; var currentCell = "answer_cell_00"+currentValue; var currentRowCell = "#javatbd"+sgq+iPlusOne+" ."+currentCell; if(document.getElementById(currentAnswer).value != "" ) { //console.log(currentRowCell); $(currentRowCell).addClass("selected-answer"); } } //highlights the td for the clicked answer. Will also remove the highlight of the old one if the answer is changed. $(".subquestions-list td").click(function() { var currentTr = "#" + $(this).closest("tr").attr("id") + " td"; //console.log(currentTr); $(currentTr).removeClass("selected-answer"); $(this).addClass("selected-answer"); }); } }); </script>