How to set up 2 SetTotal Functions on a Page

The recommended way to set up 2 SetTotal functions on a page is to set up QList arrays. (See the Javascript documentation on how to do this).


Another way to set this up is in the following example:

>purgesame~prepare compile[settot,100000,textstart=20000]{ s06:S06 Including yourself, how many people live in your household? !numeric,,,1-21 }{ s07gr:<br>S07 How many children do you or your partner have, whether or not they live at home with you?<br><br>!grid }{ s07a:a. Minor Children (Under Age 18) &nbsp;!numeric,,,0,21 }{ s07b:<br><br>b. Adult Children (Age 18+) &nbsp;!numeric,,,0,21 }{ s07c:<br><br>c. Grandchildren (Under Age 18) &nbsp;!numeric,,,0,21 }{<br><br>!display }{ !endgrid }{ !-html_labeltags }{ s08gr:S08 Thinking of who lives in your household on a regular basis, tell us how many are... (Enter zero (0) if none).!grid }{ !if [s07a#1-21]<br><br><table border="1" style="width:100%;" id="MyID">!display }>repeat $no=101,...,105;$what=&"Your Children Newborn to 1 Year Old",&"Your Children 2 to 3 Years Old",&"Your Children 4 to 7 Years Old",&"Your Children 8 to 12 Years Old",&"Your Children 13 to 17 Years Old"{ S08$no:!if [s07a#1-21]<tr><td class="qtext1" style="vertical-align: bottom; width: 70%;">$what</td><td class="tablehead" style="vertical-align: bottom; width: 30%;">!numeric,,,0-s07a }{ !if [s07a#1-21]</td></tr>!display }>end_repeat{ !if [s07a#1-21]<tr><td class="qtext1" style="vertical-align: bottom; width: 70%;"><b>Your total cannot exceed :s07a:</b></td><td class="tablehead" style="vertical-align: bottom; width: 30%;"><input readonly type="text" name="TOTALS08A" id="TOTALS08A" value="" size="3"></td></tr></table>!display }{ !if [s07b#1-21]<br><table border="1" style="width:100%;" id="MyID">!display }{ S08106:!if [s07b#1-21]<tr><td class="qtext1" style="vertical-align: bottom; width: 70%;">Your Adult Children Age 18+ Living at Home <b>(cannot exceed :s07b)</b></td><td class="tablehead" style="vertical-align: bottom; width: 30%;">!numeric,,,0-s07b }{ !if [s07b#1-21]</td></tr></table>!display }{ !if [s07c#1-21]<br><table border="1" style="width:100%;" id="MyID">!display }{ S08107:!if [s07c#1-21]<tr><td class="qtext1" style="vertical-align: bottom; width: 70%;">Your Grandchildren <b>(Under age 18, cannot exceed :s07c)</b></td><td class="tablehead" style="vertical-align: bottom; width: 30%;">!numeric,,,0-s07c }{ !if [s07c#1-21]</td></tr></table>!display }{<br><table border="1" style="width:100%;" id="MyID">!display }>repeat $no=108,...,111;$what=&"Adult Roommates (Unrelated to you)",&"Your parents or in-laws",&"Your spouse or partner",&"Other family member (aunts, uncles, cousins)"{ S08$no:<tr><td class="qtext1" style="vertical-align: bottom; width: 70%;">$what</td><td class="tablehead" style="vertical-align: bottom; width: 30%;">!numeric,,,0-s06 }{</td></tr>!display }>end_repeat{ S08112ot:<tr><td class="qtext1" style="vertical-align: bottom; width: 70%;">Someone else (Specify) !text,blank_ok,1,30 }{ S08112:</td><td class="tablehead" style="vertical-align: bottom; width: 30%;">!numeric,,,0-s06}{</td></tr></table>!display }{<br><table border="1" style="width:100%;" id="MyID"><tr><td class="qtext1" style="vertical-align: bottom; width: 70%;"><b>Your total for all people cannot exced :s06:</b></td><td class="tablehead" style="vertical-align: bottom; width: 30%;"><input readonly type="text" name="BIGTOTAL" id="BIGTOTAL" value="" size="3"></td></tr></table>!display }>repeat $no=106,...,112;&$if=&"[s07b#1-21]",&"[s07c#1-21]",&"(1=1)",&"(1=1)",&"(1=1)",&"(1=1)",&"(1=1)"{ !if $if<script type="text/javascript">build_qlist("S08$No");</script>!display }>end_repeat{<script type="text/javascript">!DISPLAY }{ !if [s07a#1-21]SetTotal("col","false","false","false",0,"S08101,S08102,S08103,S08104,S08105","TOTALS08A",":s07a:","BIGTOTAL","");!display }{SetTotal("col","false","false","false",0,qlist,"BIGTOTAL",":s06:","BIGTOTAL","");</script>!display }{ !if (checktext(s08112ot) > 0) and [s08112#0]<script type="text/javascript">window.alert("You specified someone else lives in your household but entered 0 for number of others.");</script>!endgrid_error }{ !if (checktext(s08112ot) < 1) and [s08112#1-21]<script type="text/javascript">window.alert("You specified someone else lives in your household but entered 0 for number of others.");</script>!endgrid_error }{ !if (x(s08101) + x(s08102) + x(s08103) + x(s08104) + x(s08105)) > x(s07a)<script type="text/javascript">window.alert("You stated you had a total of :s07a: minor children but your total exceeds that. Please review.");</script>!endgrid_error }{ !if (x(s08101) + x(s08102) + x(s08103) + x(s08104) + x(s08105) + x(s08106) + x(s08107) + x(s08108) + x(s08109) + x(s08110) + x(s08111) + x(s08112)) > x(s06)<script type="text/javascript">window.alert("You stated you had a total of :s06: in your household but your total on this question exceeds that. Please review.");</script>!endgrid_error }{ !endgrid }  ~end

  • settot.qpx