]> git.mjollnir.org Git - moodle.git/commitdiff
mod-survey MDL-16706 Removed inline script in survey and added survey.js
authorsamhemelryk <samhemelryk>
Thu, 25 Jun 2009 03:46:59 +0000 (03:46 +0000)
committersamhemelryk <samhemelryk>
Thu, 25 Jun 2009 03:46:59 +0000 (03:46 +0000)
mod/survey/survey.js [new file with mode: 0644]
mod/survey/view.php

diff --git a/mod/survey/survey.js b/mod/survey/survey.js
new file mode 100644 (file)
index 0000000..fba33b5
--- /dev/null
@@ -0,0 +1,26 @@
+function checkform(e) {
+    var error = false;
+    if (document.getElementById('surveyform')) {
+        var surveyform = document.getElementById('surveyform');
+        for (var i=0; i < surveycheck.questions.length; i++) {
+            var tempquestion = surveycheck.questions[i];
+            if (surveyform[tempquestion.question][tempquestion.default].checked) {
+                error = true;
+            }
+        }
+    }
+    if (error) {
+        alert(mstr.survey.questionsnotanswered);
+        YAHOO.util.Event.preventDefault(e);
+        return false;
+    } else {
+        return true;
+    }
+}
+
+function survey_attach_onsubmit() {
+    if (document.getElementById('surveyform')) {
+        var surveyform = document.getElementById('surveyform');
+        YAHOO.util.Event.addListener('surveyform', "submit", checkform);
+    }
+}
\ No newline at end of file
index 5ad0be6d0dda86428a8b8978ef3a9546a9f87b95..5c1d0946844b20655bc82813c6a6f3d5aa430461 100644 (file)
         exit;
     }
 
-?>
-
-<br />
-<script type="text/javascript">
-<!--
-function checkform() {
-
-    var error=false;
-
-    with (document.getElementById('surveyform')) {
-    <?php
-       if (!empty($checklist)) {
-           foreach ($checklist as $question => $default) {
-               echo "  if (".$question."[".$default."].checked) error=true;\n";
-           }
+    $checkarray = Array('questions'=>Array());
+    if (!empty($checklist)) {
+       foreach ($checklist as $question => $default) {
+           $checkarray['questions'][] = Array('question'=>$question, 'default'=>$default);
        }
-    ?>
     }
+    $PAGE->requires->js('mod/survey/survey.js');
+    $PAGE->requires->data_for_js('surveycheck', $checkarray);
+    $PAGE->requires->string_for_js('questionsnotanswered', 'survey');
+    $PAGE->requires->js_function_call('survey_attach_onsubmit');
 
-    if (error) {
-        alert("<?php print_string("questionsnotanswered", "survey") ?>");
-    } else {
-        document.getElementById('surveyform').submit();
-    }
-}
-
-<?php echo "document.write('<input type=\"button\" value=\"".get_string("clicktocontinuecheck", "survey")."\" onClick=\"checkform()\" />');";  ?>
-
-// END -->    
-</script>
-
-<noscript>
-    <!-- Without Javascript, no checking is done -->
-    <div>
-    <input type="submit" value="<?php  get_string("clicktocontinue", "survey") ?>" />
-    </div>
-</noscript>
-
-<?php
-   echo '</div>';
-   echo "</form>";
+    echo '<br />';
+    echo '<input type="submit" value="'.get_string("clicktocontinue", "survey").'" />';
+    echo '</div>';
+    echo "</form>";
 
-   print_footer($course);
+    print_footer($course);
 
-?>
+?>
\ No newline at end of file