Welcome, Guest
Username: Password: Remember me
  • 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 2 years 3 months ago #80879

  • Qat
  • Qat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 14
  • Karma: 0
Hello everyone

Sorry to bother you with this question, but it would take me hours to gain enough knowledge in javascript/limesurvey syntax to perform this simple task :

Context : I have a Non Mandatory Table Question and the option Hide "No answer" is active at survey level. So every line of the table initially diplays an empty row of radio buttons, but when one choice has been made for one row, the user can't revert to "no answer" (since it is hidden).

Better with an exemple : The question is "What's your opinion about the food". The rows are "Temperature, Taste, Quantity and Suited to children". The options are "Good, Neutral, Bad and (hidden) No answer"

We want the user to feel that he must answer the first rows, so we don't want to display the "no answer" option. But people without children should be able to revert to an empty row, if they mistakenly checked something.

My idea is to insert a button inside the subquestion, and use javascript to revert the radiobutton to an empty state.

FYI, I use v1.91, the question ID is 139, the Subquestion is 3x3a5, so the code I get for one on of the radiobuttons on that row is :

<input class="radio" type="radio" name="81328X6X1393x3a5" value="C04h2" id="answer81328X6X1393x3a5-C04h2" title="Neutral " onclick="noop_checkconditions(this.value, this.name, this.type)">

Can you help me with this one ?
The administrator has disabled public write access.

Re: Reset answers in a table question, using a button and javascript 2 years 3 months ago #80891

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4195
  • Thank you received: 789
  • Karma: 359
1) Set up your survey to use JavaScript.

2) Add the following script to the source of the array. Replace "QQ" with the array question ID.

The script inserts a button in each answer-text cell of the array. When clicked, the button unchecks all radios in that row.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		addReset(QQ);
 
		function addReset(qID) {
			$('#question'+qID+' th.answertext').append('<input type="button" value="Reset" class="resetButton" />');
 
			$('#question'+qID+' .resetButton').click(function(e){
				var el = $(this).parents('tr:eq(0)');
				$('input.radio', el).attr('checked', false);
			});
		}
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: kachne

Re: Reset answers in a table question, using a button and javascript 2 years 3 months ago #80910

  • Qat
  • Qat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 14
  • Karma: 0
Thanks a lot for your reply. It works just as you say.

Now if i may, I have one more question to fit perfectly my initial request :

Your solution inserts a reset button for each 'th'(row header) inside the question with the id I provide.

I would like to insert the reset button in only one specific row header.
When I inspect the code of the page, I can see that each row is enclosed in a tbody with a specidic ID. So I tried to replace the question ID by the specific tbody ID, but this didn't work :
<script type="text/javascript" charset="utf-8"> 	
$(document).ready(function(){ 		
addReset(javatbd81328X6X1393x3a5); 		
function addReset(tbID) {
  $('#tbody'+tbID+' th.answertext').append('<input type="button" value="Reset" class="resetButton" />'); 
  $('#tbody'+tbID+' .resetButton').click(function(e){
    var el = $(this).parents('tr:eq(0)');
    $('input.radio', el).attr('checked', false);
 });
 }
 });
</script>
 
Is it possible to achieve this ? What am I doing wrong ?
Thanks for your replies !
Last Edit: 2 years 3 months ago by Qat.
The administrator has disabled public write access.

Re: Reset answers in a table question, using a button and javascript 2 years 3 months ago #80924

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4195
  • Thank you received: 789
  • Karma: 359
You were close...
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		addReset('javatbd81328X6X1393x3a5');
 
		function addReset(tbID) {
			$('#'+tbID+' th.answertext').append('<input type="button" value="Reset" class="resetButton" />');
 
			$('#'+tbID+' .resetButton').click(function(e){
				var el = $(this).parents('tr:eq(0)');
				$('input.radio', el).attr('checked', false);
			});
		}
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 1 year 2 months ago #98387

  • Jules
  • Jules's Avatar
Hi everybody,

I am wondering if there is a possibility to change the positioning of the reset button. Would it be possible to…

a) …place it on the right side behind the cells with the answers (i.e.,: Question text | Option 1| Option 2| Option 3| Reset button)?

or

b) …have a reset button for the whole question (i.e., if there a five subquestions there would be one reset button which resets all choice for all five subquestions)?

Thanks in advance for any comments and suggestions!
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 1 year 2 months ago #98391

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4195
  • Thank you received: 789
  • Karma: 359
What version of LimeSurvey are you using?

Where would you want the whole-question reset button to be placed?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 1 year 2 months ago #98393

  • Jules
  • Jules's Avatar
Hi,

I am using Version 2.00+ (Build 130611) and I think the button would best fit below the subquestions, for instance in the lower right corner of the question.

Thanks a lot!
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 1 year 2 months ago #98398

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4195
  • Thank you received: 789
  • Karma: 359
To insert a row reset button for every row at the right, add this to the source of the question text:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function(){
 
		addReset('{QID}');
 
		function addReset(qID) {
			$('#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>


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>

Attachment Capture_2013-07-23.JPG not found

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: Jules

Reset answers in a table question, using a button and javascript 1 year 1 month ago #98429

  • Jules
  • Jules's Avatar
Hi Tony,

Thanks a lot for your help.

Unfortunately, the second version (add reset button for the whole question) does not work with me. I don't know what's wrong... I even tried to replicate it using the exact same layout that you used but I could not get it to work.

Concerning the first option, I have a follow up question. Using my layout, you have to scroll to access the reset button. Is there any way to avoid that?

Attachment Reset.JPG not found



I tried to add this to the template.css hoping that the remaining 15% would be taken for the reset button but the code does not affect the layout of my question at all.

#question18463 col.col-answers {
width: 25% !important;
}
#question18463 col.odd,
#question18463 col.even {
width: 20% !important;
}

Thanks again!
Julia
The administrator has disabled public write access.

Reset answers in a table question, using a button and javascript 1 year 1 month ago #98434

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6338
  • Thank you received: 819
  • Karma: 243
Julia,

For citronade, table are set to table-layout:fixed.

Than update template to have
table-layout:auto.

Denis
The administrator has disabled public write access.
The following user(s) said Thank You: Jules
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.238 seconds
Donation Image