- Posts: 10635
- Thank you received: 3698
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
It works fine for me in citronade. Have you added any other JavaScript? Any JavaScript errors?Unfortunately, the second version (add reset button for the whole question) does not work with me.
Yeah, Denis is correct, if using citronade, you need too change the table-layout rule:Using my layout, you have to scroll to access the reset button.
<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.
- lsorg
- Visitor
tpartner
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?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>
Best regards
lsorg
- tpartner
- Away
- LimeSurvey Community Team
- Posts: 10635
- Thank you received: 3698
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:
<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.
- lsorg
- Visitor
I have two dual scales side by side and want only one rest button for them.
- tpartner
- Away
- LimeSurvey Community Team
- Posts: 10635
- Thank you received: 3698
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:
$('input.radio', thisQuestion).attr('checked', false);
To this:
$('.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.
- lsorg
- Visitor
But I will keep trying.
- tpartner
- Away
- LimeSurvey Community Team
- Posts: 10635
- Thank you received: 3698
$('#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.
- Mazi
- Offline
- Official LimeSurvey Partner
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
- jonsen
- Offline
- Junior Member
- Posts: 26
- Thank you received: 3
- Maverick87Shaka
- Offline
- Senior Member
- Posts: 62
- Thank you received: 3
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:
<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.
- tpartner
- Away
- LimeSurvey Community Team
- Posts: 10635
- Thank you received: 3698
<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.
- Maverick87Shaka
- Offline
- Senior Member
- Posts: 62
- Thank you received: 3
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!