mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
mod-survey MDL-16706 Removed inline script in survey and added survey.js
This commit is contained in:
parent
c207b6bece
commit
74ef4c2e5a
26
mod/survey/survey.js
Normal file
26
mod/survey/survey.js
Normal 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
?>
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user