Welcome to the LimeSurvey Community Forum

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

validate radio and text array

  • mt9999
  • mt9999's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago #226619 by mt9999
validate radio and text array was created by mt9999
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.3.6
Own server or LimeSurvey hosting: LimeSurvey
Survey theme/template: Fruity
==================
Hi all, 
I've created this array table for participants to answer with either the radio button or numeric input (thanks to Tpartner's script)
I'm wondering how to create additional script to ensure participants answer either the radio button or the numeric input and not both. I'm looking through this thread but having trouble understanding how to change the script forums.limesurvey.org/forum/can-i-do-thi...ox-and-comment-field
My test survey is attached.
Thanks for any help!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #226621 by Joffm
Replied by Joffm on topic validate radio and text array
That's your mistake.
You use the script for an "array with comment".
But you would like to have an "array with Others" (meaning: here the options are exclusive)
Code:
<script type="text/javascript" charset="utf-8">  $(document).on('ready pjax:scriptcomplete',function(){
    // Identify the questions
    var q1ID = {QID};
    var thisQuestion = $('#question'+q1ID);
    var nextQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
    var q2ID = $(nextQuestion).attr('id').replace(/question/, '');
 
    //Hide the multiple-short-text
    nextQuestion.hide();
 
    // Move the text inputs
    $('tr.answers-list', thisQuestion).each(function(i) {
      var thisCode = $(this).attr('id').split('X')[2].split(q1ID)[1];
      $('td.answer-item:last input[type="radio"]', this).css({
        'position': 'absolute',
        'left': '-9999em'
      });
      $('td.answer-item:last', this).removeClass('radio-item').addClass('inserted-text-item').append($('input[type="text"][id$="X'+q2ID+thisCode+'"]', nextQuestion));
    });
 
    // Listeners on the text inputs
    $('input[type="text"]', thisQuestion).on('keyup change', function(e) {
      var thisRadio = $(this).closest('td').find('input[type="radio"]');
      var thisRadioVal = thisRadio.val();
      if($.trim($(this).val()) != '') {
        $(thisRadio).trigger('click');
      }
      else {
        $(thisRadio).prop('checked', false);
        thisRadioVal = '';
      }
      // Reset Expression manager
      checkconditions(thisRadioVal, $(thisRadio).attr('name'), 'radio', 'click');
    });
 
    // Listeners on the radios
    $('input[type="radio"]', thisQuestion).on('click', function(e) {
      if(!$(this).closest('td').hasClass('inserted-text-item')) {
        $(this).closest('tr').find('input[type="text"]').val('');
      }
    });
 
  });
</script>


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: mt9999

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago - 3 years 2 months ago #226628 by Joffm
Replied by Joffm on topic validate radio and text array
By the way:
I'd use a different type of question.
"multiple with comment"
Much easier to handle and easy to understand for the respondent.
Check what is used and enter the amount.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 2 months ago by Joffm.
The following user(s) said Thank You: mt9999

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose