Welcome, Guest
Username: Password: Remember me

TOPIC: Changing a column of an array (number) type question to text input

Changing a column of an array (number) type question to text input 8 months 1 week ago #102534

  • limejohn
  • limejohn's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
I have an array numbers with drop downs, but there are two questions within the array that should be text inputs and not a value to be selected from a dropdown. I haven´t been able to figure out how to change them using javascript. I tried looking in the forum at similar topics, but none of the suggested answers were for this specific type of array.

Can this be done? and if so, any tips on how to do it?
Attachments:
The administrator has disabled public write access.

Changing a column of an array (number) type question to text input 8 months 1 week ago #102544

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4127
  • Thank you received: 761
  • Karma: 347
I think the only solution would be to add some following multiple-short-text questions and then use JavaScript to hide those questions and move their text inputs into the array.

Some insights on how to do that here - www.limesurvey.org/en/forum/can-i-do-thi...ution?start=20#91170
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.

Changing a column of an array (number) type question to text input 8 months 1 week ago #102547

  • limejohn
  • limejohn's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
i have already edited my array quite a bti to get variable dropdowns and to hide some things, I tried to incorporate your code but i was not successful so i´m not sure exactly what you are doing in your code

Are you just creating an additional short text question and then adding a column to the array and replacing it with the blank text from the additional question?
The administrator has disabled public write access.

Changing a column of an array (number) type question to text input 8 months 1 week ago #102550

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4127
  • Thank you received: 761
  • Karma: 347
In your case, I would add two multiple-short-text questions and then have the JavaScript:
1) Hide those questions
2) Insert 2 new columns in the array
3) Move the text inputs from the hidden questions into the new array columns

So, this script added to the source of the array should do the trick:
<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function(){
 
		// Identify the questions
		var thisQuestion = $('#question{QID}');
		var nextMultiText1 = $(thisQuestion).nextAll('.multiple-short-txt:eq(0)');
		var nextMultiText2 = $(thisQuestion).nextAll('.multiple-short-txt:eq(1)');
 
		// Hide the next questions 
		$(nextMultiText1).hide();
		$(nextMultiText2).hide();
 
		// Add extra columns to the array
		$('table.question thead tr th:eq(2)', thisQuestion).after('<th class="newColumn1" />');
		$('table.question thead tr th:eq(4)', thisQuestion).after('<th class="newColumn2" />');
		$('table.question tbody tr', thisQuestion).each(function(i) {
			$('td:eq(2)', this).after('<td class="newColumn1" />');
			$('td:eq(4)', this).after('<td class="newColumn2" />');
		});
 
		// Move the hidden question text to the inserted columns
		$('table.question thead tr th.newColumn1', thisQuestion).text($('.questiontext', nextMultiText1).text());
		$('table.question thead tr th.newColumn2', thisQuestion).text($('.questiontext', nextMultiText2).text());
 
		// Move the text inputs and dropdowns
		$('input.text', nextMultiText1).each(function(i){
			$('table.question tbody tr:eq('+i+') td.newColumn1', thisQuestion).append(this);
		});
		$('input.text', nextMultiText2).each(function(i){
			$('table.question tbody tr:eq('+i+') td.newColumn2', thisQuestion).append(this);
		});
 
		// Some cleanup styles (for the default template)
		$('col', thisQuestion).css({
			'width': 'auto'
		});
		$('table.question tbody th, table.question tbody td', thisQuestion).css({
			'padding': '4px 10px'
		});
 
	});
</script>


Here's a working example:

File Attachment:

File Name: limesurvey_survey_966293.lss
File Size: 25 KB
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: limejohn, Gloria

Changing a column of an array (number) type question to text input 3 months 2 weeks ago #108345

  • Gloria
  • Gloria's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
Thanks Tony!
Appreciate your help.
I will try this out.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.127 seconds
Donation Image