mod-survey MDL-16706 Removed inline script in survey and added survey.js

This commit is contained in:
samhemelryk 2009-06-25 03:46:59 +00:00
parent c207b6bece
commit 74ef4c2e5a
2 changed files with 40 additions and 40 deletions

26
mod/survey/survey.js Normal file
View File

@ -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);
}
}

View File

@ -158,48 +158,22 @@
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();
}
}
echo '<br />';
echo '<input type="submit" value="'.get_string("clicktocontinue", "survey").'" />';
echo '</div>';
echo "</form>";
<?php echo "document.write('<input type=\"button\" value=\"".get_string("clicktocontinuecheck", "survey")."\" onClick=\"checkform()\" />');"; ?>
print_footer($course);
// 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>";
print_footer($course);
?>
?>