Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

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

Reset answers in a table question, using a button and javascript 3 years 6 days ago #98452

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6140
  • Thank you received: 1363
  • Karma: 535
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:
<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 administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 3 years 1 day ago #98600

  • lsorg
  • lsorg's Avatar
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: 3 years 1 day ago by lsorg.
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 3 years 1 day ago #98608

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6140
  • Thank you received: 1363
  • Karma: 535
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.
Last Edit: 3 years 1 day ago by tpartner.
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 years 11 months ago #98886

  • lsorg
  • lsorg's Avatar
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 administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 years 11 months ago #98936

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6140
  • Thank you received: 1363
  • Karma: 535
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.
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 years 11 months ago #98943

  • lsorg
  • lsorg's Avatar
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 administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 years 11 months ago #98944

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6140
  • Thank you received: 1363
  • Karma: 535
$('#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: 2 years 11 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: lsorg

Reset answers in a table question, using a button and javascript 2 years 9 months ago #100270

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5974
  • Thank you received: 366
  • Karma: 260
This is a really nice solution. Can/did you add it to the workarounds?!

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 years 9 months ago #100967

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 months 2 weeks ago #136025

  • Maverick87Shaka
  • Maverick87Shaka's Avatar
  • Offline
  • Junior Lime
  • Posts: 33
  • Thank you received: 1
  • Karma: 1
tpartner wrote:
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>

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.
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 months 2 weeks ago #136051

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6140
  • Thank you received: 1363
  • Karma: 535
Try this (no need to modify {QID}):

<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 administrator has disabled public write access.
The following user(s) said Thank You: Maverick87Shaka

Reset answers in a table question, using a button and javascript 2 months 2 weeks ago #136073

  • Maverick87Shaka
  • Maverick87Shaka's Avatar
  • Offline
  • Junior Lime
  • Posts: 33
  • Thank you received: 1
  • Karma: 1
tpartner wrote:
Try this (no need to modify {QID}):

<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 administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 months 2 weeks ago #136075

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6140
  • Thank you received: 1363
  • Karma: 535
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 administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 months 2 weeks ago #136137

  • Maverick87Shaka
  • Maverick87Shaka's Avatar
  • Offline
  • Junior Lime
  • Posts: 33
  • Thank you received: 1
  • Karma: 1
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: 2 months 2 weeks ago by Maverick87Shaka.
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 2 months 2 weeks ago #136143

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6140
  • Thank you received: 1363
  • Karma: 535
This should do the trick:

<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 administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.337 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form