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

  • lsorg
  • lsorg's Avatar
  • Visitor
  • Visitor
3 years 10 months ago #98943 by lsorg
lsorg replied the topic: Reset answers in a table question, using a button and javascript
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.

Please Log in to join the conversation.

More
3 years 10 months ago - 3 years 10 months ago #98944 by tpartner
tpartner replied the topic: Reset answers in a table question, using a button and javascript
$('#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: 3 years 10 months ago by tpartner.
The following user(s) said Thank You: lsorg

Please Log in to join the conversation.

More
3 years 8 months ago #100270 by Mazi
Mazi replied the topic: Reset answers in a table question, using a button and javascript
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)survey-consulting.com'"

Please Log in to join the conversation.

More
3 years 8 months ago #100967 by jonsen
jonsen replied the topic: Reset answers in a table question, using a button and javascript

Please Log in to join the conversation.

More
1 year 1 month ago #136025 by Maverick87Shaka
Maverick87Shaka replied the topic: Reset answers in a table question, using a button and javascript

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.

Please Log in to join the conversation.

More
1 year 1 month ago #136051 by tpartner
tpartner replied the topic: Reset answers in a table question, using a button and javascript
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 following user(s) said Thank You: Maverick87Shaka

Please Log in to join the conversation.

More
1 year 1 month ago #136073 by Maverick87Shaka
Maverick87Shaka replied the topic: Reset answers in a table question, using a button and javascript

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!

Please Log in to join the conversation.

More
1 year 1 month ago #136075 by tpartner
tpartner replied the topic: Reset answers in a table question, using a button and javascript
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.

Please Log in to join the conversation.

More
1 year 1 month ago - 1 year 1 month ago #136137 by Maverick87Shaka
Maverick87Shaka replied the topic: Reset answers in a table question, using a button and javascript
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: 1 year 1 month ago by Maverick87Shaka.

Please Log in to join the conversation.

More
1 year 1 month ago #136143 by tpartner
tpartner replied the topic: Reset answers in a table question, using a button and javascript
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.

Please Log in to join the conversation.

More
4 months 5 days ago - 4 months 5 days ago #148889 by jsibley
jsibley replied the 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.
Last Edit: 4 months 5 days ago by jsibley.

Please Log in to join the conversation.

More
4 months 5 days ago #148891 by tpartner
tpartner replied the topic: Reset answers in a table question, using a button and javascript
This should work with or without "No answer":

<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

Please Log in to join the conversation.

More
4 months 5 days ago #148892 by jsibley
jsibley replied the 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" />');

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now