Guest User

Untitled

a guest
Jan 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. // question asks them if they served in a second branch of the military
  2. // if hideAllQuestions is true, then all questions that rely on this
  3. // question and questions relying on those questions should disappear.
  4. // if showMainQuestion is true, then all immediate follow up questions
  5. var secondBranchLogic = function(hideAllQuestions = false, showMainQuestion = true)
  6. {
  7. var mainQuestionTagID = [ "#secondbranch_row" ];
  8. if (showMainQuestion) {
  9. // functions that cycle through each question in mainQuestionTagID and show them, set them to required, or hide them.
  10. enableQuestions(mainQuestionTagID);
  11. requireQuestions(mainQuestionTagID);
  12. } else {
  13. disableQuestions(mainQuestionTagID);
  14. }
  15.  
  16. // boolean logic that determines if the main question's answer should show/hide the sub questions.
  17. var answer = $("#secondbranch").val();
  18. var hasSecondBranch = ( answer === 'Yes');
  19. var showSubQuestions = (showMainQuestion && hasSecondBranch && !hideAllQuestions);
  20. // all immediate sub questions that should be shown/hidden, but not the sub questions below said sub questions.
  21. var questionTagIDs = [
  22. "#militarybranch2_row",
  23. "#militarybranch2length_row",
  24. "#militarybranch2rank_row",
  25. "#militarybranch2job_row" ];
  26.  
  27. if (showSubQuestions) {
  28. enableQuestions(questionTagIDs);
  29. requireQuestions(questionTagIDs);
  30. } else {
  31. disableQuestions(questionTagIDs);
  32. }
  33.  
  34. // boolean logic determining if dischargeLogic should hide/show some questions.
  35. var hideNextQuestions = ( answer === '' || hideAllQuestions );
  36. var showNextMainQuestion = ( !hideNextQuestions);
  37. dischargeLogic(hideNextQuestions, showNextMainQuestion);
  38. };
  39.  
  40. // question asking if they were discharged honorably
  41. // this function behaves much like the previous one.
  42. var dischargeLogic = function(hideAllQuestions = false, showMainQuestion = true)
  43. {
  44. var mainQuestionTagID = [ "#honorabledischarge_row" ];
  45. if (showMainQuestion) {
  46.  
  47. enableQuestions(mainQuestionTagID);
  48. requireQuestions(mainQuestionTagID);
  49. } else {
  50. disableQuestions(mainQuestionTagID);
  51. }
  52.  
  53. var answer = $("#honorabledischarge").val();
  54. var answered = (answer !== '');
  55. var questionTagIDs = [ "#dischargedescription_row" ];
  56. if (answered)
  57. {
  58. honorablyDischarged = (answer === 'Yes');
  59. showSubQuestion = (!honorablyDischarged && !hideAllQuestions);
  60. if (showSubQuestion) {
  61. enableQuestions(questionTagIDs);
  62. requireQuestions(questionTagIDs);
  63. } else {
  64. disableQuestions(questionTagIDs);
  65. }
  66. } else {
  67. disableQuestions(questionTagIDs);
  68. }
  69.  
  70. var hideNextQuestions = ( answer === '' || hideAllQuestions);
  71. var showNextMainQuestion = (!hideNextQuestions);
  72. deploymentsLogic(hideNextQuestions, showNextMainQuestion);
  73. };
  74.  
  75. <tr style="display:none;" id="secondbranch_row">
  76. <td class="Question">
  77. Have you served in another military branch?
  78. </td>
  79. <td style="width:100px;">
  80. <select type="text" id="secondbranch" name="secondbranch" style="width:100%;" class="needs_saved_military" required>
  81. <option value=''></option>
  82. <option value='Yes'>Yes</option>
  83. <option value='No'>No</option>
  84. </select>
  85. </td>
  86. </tr>
  87. <tr style="display:none;" id="militarybranch2_row">
  88. <td>
  89. Which branch did you serve in?
  90. </td>
  91. <td>
  92. <select type="text" id="militarybranch2" name="militarybranch2" style="width:100%;" class="needs_saved_military" required>
  93. <option value=''></option>
  94. <!-- all caps means it's a global constant array -->
  95. <?php foreach (MILITARY_BRANCH as $iBranch)
  96. {?>
  97. <option value = "<?php echo $iBranch?>"><?php echo $iBranch?> </option>
  98. <?php }?>
  99. </select>
  100. </td>
  101. </tr>
  102. <tr style="display:none;" id="militarybranch2length_row">
  103. <td>
  104. How long?
  105. </td>
  106. <td>
  107. <select type="text" id="militarybranch2length" name="militarybranch2length" style="width:100%;" class="needs_saved_military" required>
  108. <option value=''></option>
  109. <?php foreach (MILITARY_YEARS_SERVED as $iYears)
  110. {?>
  111. <option value = "<?php echo $iYears?>"><?php echo $iYears?> </option>
  112. <?php }?>
  113. </select>
  114. </td>
  115. </tr>
  116. <tr style="display:none;" id="militarybranch2rank_row">
  117. <td>
  118. What was your rank?
  119. </td>
  120. <td>
  121. <input type="text" id="militarybranch2rank" name="militarybranch2rank" style="width:100%;" class="needs_saved_military" required></input>
  122. </td>
  123. </tr>
  124. <tr style="display:none;" id="militarybranch2job_row">
  125. <td>
  126. What was your job?
  127. </td>
  128. <td>
  129. <input type="text" id="militarybranch2job" name="militarybranch2job" style="width:100%;" class="needs_saved_military" required></input>
  130. </td>
  131. </tr>
  132.  
  133. <!-- HONORABLE DISCHARGE -->
  134. <tr style="display:none;" id="honorabledischarge_row">
  135. <td class="Question">
  136. Were you honorably discharged?
  137. </td>
  138. <td style="width:100px;">
  139. <select type="text" id="honorabledischarge" name="honorabledischarge" style="width:100%;" class="needs_saved_military" required>
  140. <option value=''></option>
  141. <option value='Yes'>Yes</option>
  142. <option value='No'>No</option>
  143. </select>
  144. </td>
  145. </tr>
  146. <tr style="display:none;" id="dischargedescription_row">
  147. <td>
  148. What was the discharge?
  149. </td>
  150. <td>
  151. <input type="text" id="dischargedescription" name="dischargedescription" style="width:100%;" class="needs_saved_military" required></input>
  152. </td>
  153. </tr>
Add Comment
Please, Sign In to add comment