iFormBuilder JavaScript Tips & Tricks
When working with forms where you want to implement a scoring procedure you can utilize JavaScript Functions to evaluate the score and display it in a Final Score Field on the Form. Have a look at the example below on how to implement this functionality.
Additional Information:
Page Level Javascript
PLEASE NOTE: If you are using Subforms, you must place this page level javascript in both the Parent and Subform Forms.
STEP 1. Copy and paste the below function into the Page Level Javascript. It should look like the screenshot below.
function getScore(option) {
retVal=0;
if(option==0){retVal=1;}
else if(option==1){retVal=2;}
else if(option==2){retVal=5;}
else{retVal=0;}
return retVal;
}
In short, the javascript is saying if the first option is chosen, then the value will be 1, if the second value is chosen, the value will be 2, if the third value is chosen, the value will be 5. If all else fails, the value of the field will be 0.
STEP 2. In your form, add your option list elements. In this example, we are using Select Elements and a Number Element with Data Column Names:
Label: Question 1
Data Column Name: q1
Label: Question 2
Data Column Name: q2
Label: Question 3
Data Column Name: q3
Label: Total Score
Data Column Name: total_score
With Options: Pass, Fail and N/A
STEP 3. In your Number Element (total_score), add the following to the dynamic value:
getScore(q1)+getScore(q2)+getScore(q3)
It should look like this:
Quick Overview
Select Element 1 - Options: Pass, Fail, N/A
Data Column Name: q1
Select Element 2 - Options: Pass, Fail, N/A
Data Column Name: q2
Select Element 3 - Options: Pass, Fail, N/A
Data Column Name: q3
Number Element
Dynamic Value: getScore(q1) + getScore(q2) + getScore(q3)
Comments
0 comments
Please sign in to leave a comment.