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

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 8 months ago #98452 by tpartner

Unfortunately, the second version (add reset button for the whole question) does not work with me.

It works fine for me in citronade. Have you added any other JavaScript? Any JavaScript errors?

Using my layout, you have to scroll to access the reset button.

Yeah, Denis is correct, if using citronade, you need too change the table-layout rule:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function(){
 
    addReset('{QID}');
 
    function addReset(qID) {
      $('#question'+qID+' table.subquestions-list').css('table-layout', 'auto');
      $('#question'+qID+' table.subquestions-list thead tr').append('<th />');
      $('#question'+qID+' tr.answers-list').append('<td class="buttonCell"><input type="button" value="Reset" class="resetButton" /></td>');
 
      $('#question'+qID+' .resetButton').click(function(e){
        var parentRow = $(this).closest('tr');
        $('input.radio', parentRow).attr('checked', false);
      });
    }
  });
</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.
  • lsorg
  • lsorg's Avatar
  • Visitor
  • Visitor
10 years 7 months ago - 10 years 7 months ago #98600 by lsorg
Hello,

tpartner

To insert a question rest button below and to the right of the array, add this to the source of the question text:

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){

addReset('{QID}');

function addQuestionReset(qID) {
$('#question'+qID+' table.subquestions-list').after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');

$('#question'+qID+' .resetQuestionButton').click(function(e){
var parentQuestion = $(this).closest('.array-flexible-row');
$('input.radio', parentQuestion).attr('checked', false);
});
}
});
</script>

The code works very well. But not for array dual scale. Knows everyone how I have to change the code that the reset button works with the array dual scale?

Best regards
lsorg
Last edit: 10 years 7 months ago by lsorg.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 7 months ago - 10 years 7 months ago #98608 by tpartner

Knows everyone how I have to change the code that the reset button works with the array dual scale?


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>

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 topic has been locked.
  • lsorg
  • lsorg's Avatar
  • Visitor
  • Visitor
10 years 7 months ago #98886 by lsorg
Is it possible to set one reset button for two question which are in the same question group?

I have two dual scales side by side and want only one rest button for them.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 7 months ago #98936 by tpartner

Is it possible to set one reset button for two question which are in the same question group?

I have two dual scales side by side and want only one rest button for them.


To reset all radios in all dual-scale-arrays on a page, change this:
Code:
$('input.radio', thisQuestion).attr('checked', false);

To this:
Code:
$('.array-flexible-duel-scale input.radio').attr('checked', false);

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • 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
  • Away
  • 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 5 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
  • Away
  • 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.

Lime-years ahead

Online-surveys for every purse and purpose