- Posts: 62
- Thank you received: 3
Ask the community, share ideas, and connect with other LimeSurvey users!
<p>Some question text...</p> <p>You have spent <b><span class="points-count">0</span></b> points of 150 available</p> <script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Listener on the radio buttons $('input:radio', thisQuestion).on('click', function(e) { var points = 0; $('tr.answers-list:visible input:radio:checked', thisQuestion).each(function(i) { points = points + Number($(this).val()); }); $('span.points-count', thisQuestion).text(points); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); var btSubmit = document.getElementById('ls-button-submit'); // Listener on the radio buttons $('input:radio', thisQuestion).on('click', function(e) { var points = 0; $('tr.answers-list:visible input:radio:checked', thisQuestion).each(function(i) { points = points + Number($(this).val()); }); $('span.points-count', thisQuestion).text(points); if (points > 50) { btSubmit.disabled = true; } else { btSubmit.disabled = false; } }); }); </script>
control1 <= 50
<p>{if(control1 <= 50, 'You may use up to 50 points', '<span class="text-danger">Warning, you must not exceed 50 points!</span>')}</p> <script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); var arrayQuestion = $(thisQuestion).prevAll('.question-container:eq(0)'); // Listener on the radio buttons $('input:radio', arrayQuestion).on('click', function(e) { var points = 0; $('tr.answers-list:visible input:radio:checked', arrayQuestion).each(function(i) { points = points + Number($(this).val()); }); $('input:text', thisQuestion).val(points).trigger('change'); }); // Hide some elements $('.question-valid-container, .answer-container', thisQuestion).hide(); }); </script>