- Posts: 72
- Thank you received: 17
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if($('#question{QID} input.radio:checked').length > 0) { radio.disabled = true; } }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('#question{QID} input.radio').on('click', function(e){ $('#question{QID} input.radio').not(this).prop('disabled', true); }); }); </script>
tpartner wrote: Try this:
Code:<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('#question{QID} input.radio').on('click', function(e){ $('#question{QID} input.radio').not(this).prop('disabled', true); }); }); </script>
holch wrote: Hmmm, I think I was judging too quick. I was using the same question for another issue to test something and I noticed that when you click on the answer option instead of the radio button, the radio buttons stay the same, but the response changes...
Oops, forgot about the labels - try this:Hmmm, I think I was judging too quick. I was using the same question for another issue to test something and I noticed that when you click on the answer option instead of the radio button, the radio buttons stay the same, but the response changes...
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('#question{QID} input.radio').on('click', function(e){ $('#question{QID} input.radio').not(this).prop('disabled', true); $('#question{QID} input.radio:checked').prop('disabled', false); }); }); </script>
<script type="text/javascript" charset="utf-8"> $('#question{QID} input.radio').on('click', function(e){ $('#question{QID} input.radio').not(this).prop('disabled', true); $('#question{QID} input.radio:checked').prop('disabled', false).trigger('click'); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // A function to disable all non-checked radios function handleDisableNonChecked(thisRadio) { var thisRow = $(thisRadio).closest('.answer-item'); // Disable non-checked radios $('#question{QID} input.radio').not(thisRadio).prop('disabled', true); // Handle "Other" text input if($('input.text', thisRow).length == 0) { $('#question{QID} input.text').prop('disabled', true); } // Add a class to the disabled rows $('#question{QID} .answer-item').not(thisRow).addClass('disabled-row'); } // Initial state (in case of returning to page if($('#question{QID} input.radio:checked').length > 0) { handleDisableNonChecked($('#question{QID} input.radio:checked')); } // Listener on the radios $('#question{QID} input.radio').on('click', function(e){ handleDisableNonChecked(this); }); // Fix the core event handler for the label div $('#question{QID} .label-clickable').unbind('click').on('click', function(e){ if(!$(this).parent().find('input.radio').is(':disabled')) { $(this).parent().find('input.radio').trigger('click'); } }); }); </script>
.disabled-row .label-clickable{ opacity: 0.45; cursor: not-allowed; }
So your latter solution is preferred and works great!3) Handles initial states in case of returning to the group