Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Display number of rows in array question based on previous numerical input

Display number of rows in array question based on previous numerical input 8 months 3 days ago #113895

  • zer0mode
  • zer0mode's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
Hi, after variety solutions and posts red on this forum i consider myself no more than a fresh beginner in LS environment and even less in javascript.

As an introduction to my survey I'd like to construct a set of similar questions as the OP. That is reading a number which toggles row visibility in the following question. Does this solution here work with version 2.05+ ?

Alternative convenient solution would be to use Variable Length Array, which also didn't work for me. I've found this correction, but without luck. Finally i've tried to alter the simplified version to make it work with "array-multi-flexi-text", but without success.

Can someone give a feedback about functionality of those codes with the latest version of LS ?

As I am not at all experienced with javascript I was bouncing during a long time around the idea of subquestion relevance, but then found out that this might be implemented in the version 2.06.
Last Edit: 8 months 3 days ago by zer0mode. Reason: expressions correction
The administrator has disabled public write access.

Display number of rows in array question based on previous numerical input 8 months 2 days ago #113906

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 4954
  • Thank you received: 1017
  • Karma: 422
This works in 2.05:

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function(){
 
		// Identify the questions
		var q1ID = '{QID}';
		var q1 = $('#question'+q1ID+'');
		var q2 = $(q1).nextAll('.array-multi-flexi-text:eq(0)'); 
		var q2ID = $(q2).attr('id').split('question')[1];
 
		// Initial row handling
		handleRows($('input[type="text"]', q1));
 
		// Listener on the numeric input
		$('input[type="text"]', q1).change(function(){
			var maxRows = $('tr.subquestion-list', q2).length;
			if($(this).val() > maxRows) {
				alert('You can only display a maximum of '+maxRows+' rows!');
				$(this).val('');
			}
			else {
				handleRows(this);
			}
		});
 
		function handleRows(el) {
			var numRows = $(el).val();
			$('tr.subquestion-list', q2).hide();
			$('tr.subquestion-list', q2).each(function(i){
				if(i >= numRows) {
					$('input[type="text"], select', this).val('');
				}
				else {
					$(this).show();
				}
			})
		}
	});
</script>

File Attachment:

File Name: limesurvey...4517.lss
File Size:19 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: zer0mode

Display number of rows in array question based on previous numerical input 1 week 6 days ago #121765

  • Remundo
  • Remundo's Avatar
  • Offline
  • Platinum Lime
  • Posts: 470
  • Thank you received: 33
  • Karma: 11
Hello,
Have you found a solution to this problem?
ricardo wrote:
Hi Tony,

There small glitch in this workaround

The rows don't display as soon as the number is entered...they only show up after clicking somewhere else...is there a way to make the rows appear as soon as the number is entered.




this is a link to the question broaderimpacts.org/surveys/limesurvey/index.php/289571/lang-en

rg
Rémi Biscueil
Technicien en production et analyse de données
Service de l'évaluation, des études et du pilotage
15, Rue de l'Hôtel Dieu 86022 POITIERS Cedex
The administrator has disabled public write access.

Display number of rows in array question based on previous numerical input 1 week 6 days ago #121769

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 4954
  • Thank you received: 1017
  • Karma: 422
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.

Display number of rows in array question based on previous numerical input 1 week 6 days ago #121770

  • Remundo
  • Remundo's Avatar
  • Offline
  • Platinum Lime
  • Posts: 470
  • Thank you received: 33
  • Karma: 11
I saw but it was only in relation to mouse movement and not if only changes the value at the keyboard!
Rémi Biscueil
Technicien en production et analyse de données
Service de l'évaluation, des études et du pilotage
15, Rue de l'Hôtel Dieu 86022 POITIERS Cedex
The administrator has disabled public write access.

Display number of rows in array question based on previous numerical input 1 week 6 days ago #121771

  • Remundo
  • Remundo's Avatar
  • Offline
  • Platinum Lime
  • Posts: 470
  • Thank you received: 33
  • Karma: 11
keyup is good :-)
Rémi Biscueil
Technicien en production et analyse de données
Service de l'évaluation, des études et du pilotage
15, Rue de l'Hôtel Dieu 86022 POITIERS Cedex
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.187 seconds