- Posts: 112
- Thank you received: 6
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Get current and previous questions var thisQuestion = $('#question{QID}'); var prevQuestion = thisQuestion.prev('.question-container'); $(':radio', prevQuestion).on('change', function(i) { // Get value of previous question var selectedOption = $(':radio:checked', prevQuestion).val(); // Hide answer options based on selectedOption if(selectedOption == 1) { $(thisQuestion . "option[value='4']").remove(); $(thisQuestion . "option[value='5']").remove(); $(thisQuestion . "option[value='6']").remove(); $(thisQuestion . "option[value='7']").remove(); $(thisQuestion . "option[value='8']").remove(); $(thisQuestion . "option[value='9']").remove(); } else if (selectedOption == 2) { $(thisQuestion . "option[value='1']").remove(); $(thisQuestion . "option[value='2']").remove(); $(thisQuestion . "option[value='3']").remove(); $(thisQuestion . "option[value='7']").remove(); $(thisQuestion . "option[value='8']").remove(); $(thisQuestion . "option[value='9']").remove(); } else if (selectedOption == 3) { $(thisQuestion . "option[value='1']").remove(); $(thisQuestion . "option[value='2']").remove(); $(thisQuestion . "option[value='3']").remove(); $(thisQuestion . "option[value='4']").remove(); $(thisQuestion . "option[value='5']").remove(); $(thisQuestion . "option[value='6']").remove(); } }); }); </script>
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); var prevQuestion = thisQuestion.prev('.question-container'); $('.answer-item :radio', prevQuestion).on('click', function(i) { // Reset the drop-down $('select.form-control').val('').trigger('change'); $("select.form-control option", thisQuestion).show(); // Get value of previous question var selectedValue = $(this).val(); // Hide answer options based on selectedValue if(selectedValue == 1) { $("select.form-control option[value='4']", thisQuestion).hide(); $("select.form-control option[value='5']", thisQuestion).hide(); $("select.form-control option[value='6']", thisQuestion).hide(); $("select.form-control option[value='7']", thisQuestion).hide(); $("select.form-control option[value='8']", thisQuestion).hide(); $("select.form-control option[value='9']", thisQuestion).hide(); } else if (selectedValue == 2) { $("select.form-control option[value='1']", thisQuestion).hide(); $("select.form-control option[value='2']", thisQuestion).hide(); $("select.form-control option[value='3']", thisQuestion).hide(); $("select.form-control option[value='7']", thisQuestion).hide(); $("select.form-control option[value='8']", thisQuestion).hide(); $("select.form-control option[value='9']", thisQuestion).hide(); } else if (selectedValue == 3) { $("select.form-control option[value='1']", thisQuestion).hide(); $("select.form-control option[value='2']", thisQuestion).hide(); $("select.form-control option[value='3']", thisQuestion).hide(); $("select.form-control option[value='4']", thisQuestion).hide(); $("select.form-control option[value='5']", thisQuestion).hide(); $("select.form-control option[value='6']", thisQuestion).hide(); } }); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); var prevQuestion = thisQuestion.prev('.question-container'); // Define the excluded options var excludes = { '1': [4, 5, 6, 7, 8, 9], '2': [1, 2, 3, 7, 8, 9], '3': [1, 2, 3, 4, 5, 6] } $('.answer-item :radio', prevQuestion).on('click', function(i) { // Reset the drop-down $('select.form-control').val('').trigger('change'); $("select.form-control option", thisQuestion).show(); // Get value of previous question var selectedValue = $(this).val(); // Hide answer options based on selectedValue $.each(excludes[selectedValue], function(i, val) { $('select.form-control option', thisQuestion).filter(function () { return $(this).val() == val; }).hide() }); }); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.