The LimeSurvey Fund-Raiser 2012 is complete. Thank you for donating a total of 25,000 USD!     List of donors »

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

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

Array (number) - Creating Unique Ranges for Subquestions (Min, Max) 9 months 2 days 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) 9 months 2 hours ago #84735

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2853
  • Thank you received: 423
  • Karma: 243
Do you want a pop-up alert when a wrong value is entered or simply not allow it (like a mask)?
Cheers,
Tony

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) 9 months 27 minutes 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) 8 months 4 weeks ago #84795

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2853
  • Thank you received: 423
  • Karma: 243
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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
  • Page:
  • 1
Moderators: DenisChenu, ITEd
Time to create page: 0.221 seconds
Donation Image