Welcome to the LimeSurvey Community Forum

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

Reset answers in a table question, using a button and javascript

  • lsorg
  • lsorg's Avatar
  • Visitor
  • Visitor
10 years 7 months ago #98943 by lsorg
Thanks for the code, but with .array-flexible-dual-scale it resets each dual scale on the page an I only want that it reset two specifc scales with ID 775 and 1066.

But I will keep trying.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 7 months ago - 10 years 7 months ago #98944 by tpartner
Code:
$('#question775 input.radio, #question1066 input.radio').attr('checked', false);

;)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 7 months ago by tpartner.
The following user(s) said Thank You: lsorg
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
10 years 5 months ago #100270 by Mazi
This is a really nice solution. Can/did you add it to the workarounds?!

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
More
10 years 4 months ago #100967 by jonsen
The topic has been locked.
More
7 years 10 months ago #136025 by Maverick87Shaka

tpartner wrote: Here is a more generic version of the code:

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function(){
 
    addReset('{QID}');
 
    function addQuestionReset(qID) {
      var thisQuestion = $('#question'+qID+'');
 
      $('table.subquestions-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
 
      $('#question'+qID+' .resetQuestionButton').click(function(e){
        $('input.radio', thisQuestion).attr('checked', false);
      });
    }
  });
</script>


Hi to all,
I know it's a really old post, but i really need the same function in my survey today.
Anyone can help me to adapt the code to the version: Version 2.50+ Build 160504 .

I try the "simple alert" code to test if javascript is working and i have the pop-up with the alert message like suggested in the limesurvey guide.
Unfortunate the code for my array dual scale question doesn't work:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function(){
 
    addReset('19');
 
    function addQuestionReset(qID) {
      var thisQuestion = $('#question'+qID+'');
 
      $('table.subquestions-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
 
      $('#question'+qID+' .resetQuestionButton').click(function(e){
        $('input.radio', thisQuestion).attr('checked', false);
      });
    }
  });
</script>

Where 19 is the ID of my question test.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #136051 by tpartner
Try this (no need to modify {QID}):

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function(){
 
    addQuestionReset('{QID}');
 
    function addQuestionReset(qID) {
      var thisQuestion = $('#question'+qID+'');
 
      $('table.subquestion-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
 
      $('#question'+qID+' .resetQuestionButton').click(function(e){
        $('input.radio', thisQuestion).prop('checked', false);
      });
    }
  });  
</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: Maverick87Shaka
The topic has been locked.
More
7 years 10 months ago #136073 by Maverick87Shaka

tpartner wrote: Try this (no need to modify {QID}):

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function(){
 
    addQuestionReset('{QID}');
 
    function addQuestionReset(qID) {
      var thisQuestion = $('#question'+qID+'');
 
      $('table.subquestion-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
 
      $('#question'+qID+' .resetQuestionButton').click(function(e){
        $('input.radio', thisQuestion).prop('checked', false);
      });
    }
  });  
</script>


Yes! This is finally working on the new version, thanks so much!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #136075 by tpartner
This is nothing, wait until you see your other post :)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 10 months ago - 7 years 10 months ago #136137 by Maverick87Shaka
Using reset button in the array works very well.
We have just a little "issues" made by the logic of my survey.
Currently I'm using the array question type, with the option to to force the user to select only 2 sub-question of 3 available ( Minimum/Maximum answers: 2 )

When you enable this feature, under the question title you have a "TIPS" that make a remind to the user to select 2 answers. This tips are nice and dynamic, that becomes green colored when the user responds correctly at the array.

Using Reset question as is coded right now, the radio button selection was deleted but the TIPS wasn't reset too ( remains green even no selection is made ). There is a way to reset also tips logic of that question at the same time?
Last edit: 7 years 10 months ago by Maverick87Shaka.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #136143 by tpartner
This should do the trick:

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function(){
 
    addQuestionReset('{QID}');
 
    function addQuestionReset(qID) {
      var thisQuestion = $('#question'+qID+'');
 
      $('table.subquestion-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
 
      $('.resetQuestionButton', thisQuestion).click(function(e){
        $('input.radio', thisQuestion).prop('disabled', false);
        $('input.radio:checked', thisQuestion).each(function(i) {
          $(this).prop('checked', false);
          checkconditions('', this.name, this.type);  
        });
      });
    }
  });  
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 3 weeks ago - 7 years 3 weeks ago #148889 by jsibley
This seems really helpful, but what if I would like to reset the answers in an array to "no answer"? In this version, even that is deselected.

I'm using version 2.5, btw.

Many thanks.
Last edit: 7 years 3 weeks ago by jsibley.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 weeks ago #148891 by tpartner
This should work with or without "No answer":

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
 
    addQuestionReset('{QID}');
 
    function addQuestionReset(qID) {
      var thisQuestion = $('#question'+qID+'');
 
      $('table.subquestion-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
 
      $('.resetQuestionButton', thisQuestion).click(function(e){
        if($('input.radio[value=""]', thisQuestion).length > 0) {
          $('input.radio[value=""]', thisQuestion).trigger('click');
        }
        else {
          $('input.radio', thisQuestion).prop('disabled', false).prop('checked', false);
        }
        $('input.radio', thisQuestion).each(function(i) {
          checkconditions(this.value, this.name, this.type);  
        });
      });
    }
  });  
</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: jsibley
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose