Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Script para limpiar valores en respuesta multiple con opción "Ninguno" o "N/A"

More
1 year 6 months ago #269924 by percyherrera
Ayúdenos a ayudarle y rellene los siguientes campos:.
Su versión de LimeSurvey: 6.12.3
Servidor propio o LimeSurvey Cloud: LimeSurvey Cloud
Plantilla de diseño utilizada: vanilla
==================
Amigos, comparto el siguiente script que utilizo para el siguiente escenario: Imaginemos que tenemos una pregunta de tipo respuesta multiple con varios items en una columna y en el ultimo campo tenemos la opción "Ninguno" o "N/A". La idea es que si selecciono el item "Ninguno" se desmarquen los otros items y si selecciono cualquiera de los items validos se desmarque la opción "Ninguno" si estuviera seleccionada.  Esto lo he podido lograr con el siguiente script y lo comparto para usarlo en un futuro.
Espero sea de ayuda:
Code:
<script type="text/javascript" charset="utf-8">   $(document).ready(function() {     // Call the exclude function using question ID     excludeOpt({QID});   });   // A function to make the last option in a single-column multiple choice exclusive   function excludeOpt(qID) {     var thisQuestion = $('#question' + qID);     // Add classes to the checkbox items     $('input[type="checkbox"]', thisQuestion).each(function(i) {       $(this).closest('li').addClass('normal-item');     });     // Mark the last checkbox as exclusive     $('li.normal-item:last', thisQuestion).removeClass('normal-item').addClass('exclusive-item');     // A listener on the checkboxes     $('input[type="checkbox"]', thisQuestion).on('change', function(event) {       handleExclusive($(this).closest('li'));     });     function handleExclusive(thisItem) {       // Uncheck the appropriate boxes       if ($(thisItem).hasClass('normal-item')) {         $('.exclusive-item input[type="checkbox"]', thisQuestion).prop('checked', false);       } else {         $('.normal-item input[type="checkbox"]', thisQuestion).prop('checked', false);       }       // Check conditions (relevance)       $('li.checkbox-item', thisQuestion).each(function(i) {         var thisValue = '';         if ($('input[type="checkbox"]', this).is(':checked')) {           thisValue = 1;         }         var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');         $('input[type="hidden"]', this).attr('value', thisValue);         fixnum_checkconditions(thisValue, thisSGQA, 'hidden');       });     }   } </script>

Please Log in to join the conversation.

Moderators: holch, tpartner

Lime-years ahead

Online-surveys for every purse and purpose