- Posts: 10110
- Thank you received: 3593
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
- Away
- LimeSurvey Community Team
Less
More
7 years 11 months ago #136143
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Reset answers in a table question, using a button and javascript
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.
- jsibley
- Offline
- Senior Member
Less
More
- Posts: 40
- Thank you received: 0
7 years 2 months ago - 7 years 2 months ago #148889
by jsibley
Replied by jsibley on topic Reset answers in a table question, using a button and javascript
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.
I'm using version 2.5, btw.
Many thanks.
Last edit: 7 years 2 months ago by jsibley.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3593
7 years 2 months ago #148891
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Reset answers in a table question, using a button and javascript
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.
- jsibley
- Offline
- Senior Member
Less
More
- Posts: 40
- Thank you received: 0
7 years 2 months ago #148892
by jsibley
Replied by jsibley on topic Reset answers in a table question, using a button and javascript
This is exactly what I was hoping for, thank you.
And, in case it isn't obvious to anyone, you can put the reset button above the array question by changing:
$('table.subquestion-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
to
$('table.subquestion-list', thisQuestion).before('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
And, in case it isn't obvious to anyone, you can put the reset button above the array question by changing:
$('table.subquestion-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
to
$('table.subquestion-list', thisQuestion).before('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
The topic has been locked.