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

TOPIC: Sum values different questions

Sum values different questions 4 years 5 months ago #58294

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5095
  • Thank you received: 1047
  • Karma: 440
You shouldn't need it with a multi-numeric - there is a built-in max/min setting:

This message has an attachment image.
Please log in or register to see it.

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.

Sum values different questions 4 years 5 months ago #58347

  • rocio
  • rocio's Avatar
  • Offline
  • Junior Lime
  • Posts: 34
  • Karma: 0
Hello,
I have a multiple numerical input, and maximum and minimum value does not work, because if the sum gives me 20%, and is within these values ​​let you continue. I want the sum is equal to zero or 100, but no other value, so I wanted to use the script to do that identifiers eso.Pero I have to wear?
Thanks.
The administrator has disabled public write access.

Sum values different questions 4 years 5 months ago #58444

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5095
  • Thank you received: 1047
  • Karma: 440
Sorry to take so long to reply Steven.

This will tally all of the inputs in a multiple numbers question and prevent survey advancing unless the tally is 0 or 100. (replace "11" with the multi-numbers ID)
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){ 
 
		$('form#limesurvey').submit(function(){
 
			var qID = 11;
 
			var totalSum = 0;
 
			// Tally up all inputs
			$('#question'+qID+' input.text').each(function(i) {
				var inputVal = $(this).val();
				if (inputVal) {
					totalSum = Number(totalSum) + Number(inputVal);
				}
			});
 
			if(totalSum == 0 || totalSum == 100) {
				return true;
			}
			else {
				return false;
			}
		});
	});
 
</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.

Sum values different questions 4 years 5 months ago #58487

  • steven8000
  • steven8000's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 16
  • Karma: 0
thanks!
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.128 seconds