- Posts: 5055
- Thank you received: 1267
Ask the community, share ideas, and connect with other LimeSurvey users!
sum(questioncode_1.NAOK == 'Y', questionscode_2.NAOK == 'Y', ....
{list(questioncode.shown)}
Which car(s) do you own? <script type="text/javascript" charset="utf-8"> $(document).ready(function() { //// Identify the hidden question input //// EDIT HERE (1) - replace with your hidden question input ID var hiddenInput = 'answer#119459X725X11680'; //// Identify the checkboxes to be randomized //// EDIT HERE (3) - add or remove as required, //// replace with your checkbox IDs var CB1 = '#answer119459X725X11664A'; var CB2 = '#answer119459X725X11664B'; var CB3 = '#answer119459X725X11664C'; //// Create an array of all checkboxes to be randomized //// EDIT HERE (4) - add or remove CBs as required checkBoxes = new Array( CB1, CB2, CB3 ); var checkBoxesLength = checkBoxes.length; //// The randomizing function - no editing required function randomResponse () { var boxLabels = new Array(); // loop through all of the checkboxes and if they are checked, // add their label to the boxLabels array for( var i=0; i<checkBoxesLength; i++ ) { if ( $(checkBoxes[i]).attr('checked') == true ) { var cbid = checkBoxes[i].replace('#',''); boxLabels.push( $( 'label[for=' + cbid + ']' ).html() ); } } // find a random index of the responses array var randomNum = Math.floor(Math.random() * boxLabels.length); // populate the hidden question input with the // random input value $(hiddenInput).val( boxLabels[randomNum] ); } //// The listeners that will fire the randomize function if a //// change occurs in the checkboxes //// EDIT HERE (5) - add or remove CBs as required $(CB1).change(function() { randomResponse (); }); $(CB2).change(function() { randomResponse (); }); $(CB3).change(function() { randomResponse (); }); }); </script>