Adding Sum Check Validation

Home / DatStat Illume Product Documentation / Validation / Adding Sum Check Validation

The following example demonstrates how to add sum check validation.  In this example, let’s assume we want the sum of these questions to add up to 100.

  • Make sure the survey you are editing adheres to the Survey requirements for using Ranking/Sum Check validation.
  • Add 5 questions to a question table and set the variable names to ‘Q1′ through ‘Q5′.
  • Make sure the data type of these questions is Whole Numbers and the display type is set to Text Field.
  • Click the Source tab of the question table Instructions field and append the following HTML content that allows for a running total to be displayed:
    <P>Current Total: <SPAN id=TOTAL style=”FONT-WEIGHT: bold;COLOR: red”</SPAN
  • Add a Text/HTML object IMMEDIATELY FOLLOWING the question table created above.
  • Click the Source tab of the Text/HTML object created in the previous step and insert the following content:

<script language="JavaScript">

function setTotal(total, ok)

{
var display = document.getElementById("TOTAL");

if(!display || typeof display == 'undefined')
return;
display.innerHTML = total + "%";

if(ok)
display.style.color = 'green';
else
display.style.color = 'red';

}

DatStat.addClientValidationCheck(new DatStat.SumCheckValidation(

['{FormElement:Q7}', '{FormElement:Q8}', '{FormElement:Q9}'], /* Question array list */
100,   /* Minimum sum */
100,   /* Maximum sum */
true,
setTotal,  /* Callback function */

'Total must equal 100.  Current total is {0}.' /* Error Message */
));

</script>

SumCheckValidation Parameters

The SumCheckValidation parameters are separated by commas and must appear in the order as listed below.

Question List Array

This value should be a comma-delimited list of single-quoted text values that are the form element names of the questions to be ranked all enclosed between beginning and end brackets (‘[‘ and ‘]’). The {FormElement:} tag is normally used to specify the form element names for each of the questions.

Example:

['{FormElement:Q1}', '{FormElement:Q2}', '{FormElement:Q3}' ]

Minimum Allowed Sum

This is a numeric value that is the minimum allowed by the sum check validation code.  This value should be less than or equal to the maximum allowed sum (i.e. the next parameter).

Maximum Allowed Sum

This is a numeric value that is the maximum allowed by the sum check validation code.  This value should be greater than or equal to the minimum allowed sum (i.e. the previous parameter).

Callback Function

This is an optional argument. If not set to null, this argument should be a JavaScript function object that accepts 2 arguments:  1) the current running ‘total’; and 2) whether or not this value is ‘ok’ and fulfills the sum check minimum/maximum requirements.  This function is called whenever the sum of the questions changes.

Error Message

This is a text message enclosed in single-quotes.  It is displayed if the sum of the responses isn’t between the required minimum/maximum values.  This error message can contain the following tag: {0} which will be replaced with the current total.

Warning Only (Optional)

This is a true/false option.  Set this option to true if you want the validation to be a warning only, with the ability to continue or to stay on the page and make changes.  This is also known as “soft” validation.  If this value is not specified, it will default to false.