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

More
5 years 2 months ago #84676 by simek
simek created the topic: Array (number) - Creating Unique Ranges for Subquestions (Min, Max)
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?

Please Log in to join the conversation.

More
5 years 2 months ago #84735 by tpartner
tpartner replied the topic: Array (number) - Creating Unique Ranges for Subquestions (Min, Max)
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.

Please Log in to join the conversation.

More
5 years 2 months ago #84736 by simek
simek replied the topic: Array (number) - Creating Unique Ranges for Subquestions (Min, Max)
I just want to disallow it.

Please Log in to join the conversation.

More
5 years 2 months ago #84795 by tpartner
tpartner replied the topic: Array (number) - Creating Unique Ranges for Subquestions (Min, Max)
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.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now