Welcome to the LimeSurvey Community Forum

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

Hiding multiple choice with comments text box and more

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #105363 by tpartner
Since the inclusion of Expression Manager we need to have a space or line-break after all opening curly braces and before all closing curly braces. (don't get me started on the whole "valid JavaScript" discussion again)

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() { 
 
    var q1ID = 68;
    var msg = 'Please specify in the comment box.';
 
    // Hide the first 3 text inputs of Q1
    $('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide();
    $('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide();
    $('#question'+q1ID+' li[id^="javatbd"]:eq(2) .comment').hide();
 
    // Interrupt next/submit function 
    $('#movenextbtn, #movesubmitbtn').click(function(){
 
      // Reset some stuff
      var failedMandatory = 0;
      $('#question'+q1ID+' input.text').css({ 
        'background':'' 
      });
 
      // Loop through all check answers in Q1
      $('#question'+q1ID+' input.checkbox:checked').each(function(i){
 
        // Define the row
        var thisRow = $(this).parents('li:eq(0)');
 
        // Check for empty mandatory text inputs
        if($('input.text:visible', thisRow).length > 0 &amp;&amp; $('input.text', thisRow).val() == '') {
          $('input.text', thisRow).css({
            'background':'pink'
          });
          failedMandatory = 1;
        }
      });  
 
      // Abort submit if any mandatory text inputs are empty
      if(failedMandatory == 1) {
        alert (msg);
        return false;  
      }
      else {
        return true;  
      }
    });
  });
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: AGK925
The topic has been locked.
More
10 years 1 month ago #105402 by AGK925
Thank you very much for your help. It works brilliantly, I spent a lot of time looking for solutions but apparently missed out on the basics of writing the scripts within a question. Now that I have gotten past this hurdle I think it would be wise to spend time learning the basics.

Again thank you very much for your help. This was my first attempt to use LimeSurvey and it seems like it is a great tool for creating online surveys with a wonderfully helpful community.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose