Welcome, Guest
Username: Password: Remember me

TOPIC: Array (number) - Creating Unique Ranges for Subquestions (Min, Max)

Array (number) - Creating Unique Ranges for Subquestions (Min, Max) 2 years 3 months ago #84676

  • simek
  • simek's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
I just started using LS . . .great software. I searched the forum, and could not find my answer, so here is my question.

BTW .....using version 1.92.

I have a question {array (number)} that asks time of day . . .first ask for hour then minute. How do I set unique min, max values for hour (0-12) and minutes (00-60) in the same question?
The administrator has disabled public write access.

Re: Array (number) - Creating Unique Ranges for Subquestions (Min, Max) 2 years 3 months ago #84735

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4372
  • Thank you received: 830
  • Karma: 381
Do you want a pop-up alert when a wrong value is entered or simply not allow it (like a mask)?
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.

Re: Array (number) - Creating Unique Ranges for Subquestions (Min, Max) 2 years 3 months ago #84736

  • simek
  • simek's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
I just want to disallow it.
The administrator has disabled public write access.

Re: Array (number) - Creating Unique Ranges for Subquestions (Min, Max) 2 years 3 months ago #84795

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4372
  • Thank you received: 830
  • Karma: 381
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 puts listeners on the text inputs and if a number less than 0 or greater than the max value for that column is detected the value is reverted to the last valid one.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		hoursMinutes(QQ, 12, 60);
 
		function hoursMinutes(qID, col1Max, col2Max) {
 
			// Load existing answers into memory
			var answers = new Object();
			$('#question'+qID+' input:[type="text"]').each(function(i){
				answers[$(this).attr('id')] = $(this).val();
			});
 
			// Assign some classes
			$('#question'+qID+' table.question tbody tr').each(function(i){
				$('input:[type="text"]', this).each(function(i){
					$(this).addClass('column-'+(i+1));
				});
			});
 
			// Listeners on the inputs
			$('#question'+qID+' input:[type="text"]').change(function(){
				if($(this).hasClass('column-1')) {
					var maxNum = col1Max;
				}
				else {
					var maxNum = col2Max;
				}
				if($(this).val() < 0 || $(this).val() > maxNum) { // Fail - revert to answer in memory
					$(this).val(answers[$(this).attr('id')]);
				}
				else { // Pass - update answer in memory
					answers[$(this).attr('id')] = $(this).val();
				}			
			});
		}
 
	});
 
</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.
Moderators: ITEd
Time to create page: 0.110 seconds
Donation Image