I'm new to moodle development. I included Javascript following the guidelines, but It's not working
Here is my block content code below, I added javascript in blocks/coursetopics/amd/src/myfile.js, the javascript content of my code is below the php code
May I know where I went wrong. I also included the content of my console on chrome at the bottom
public function get_content() {
global $OUTPUT, $DB, $PAGE, $CFG;
$CFG->cachejs = false;
$PAGE->requires->js_call_amd('block_coursetopic/myfile', 'init');
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass();
$this->content->footer = '';
// Add logic here to define your template data or any other content.
$courses = $DB->get_records_sql('SELECT id, fullname FROM mo_course');
$dropdown ='<select id="select_course">';
$dropdown .='<option value="">Select Course Topic</option>';
foreach($courses as $course) {
if($course->id == 1) {
continue;
}
$dropdown .="<option value='".$course->id."'>".$course->fullname."</option>";
}
$dropdown .="</select>";
$this->content->text = $dropdown;
return $this->content;
}
Javascript myfile.js content
define(['jquery'], function($) {
return {
init: function() {
// Put whatever you like here. $ is available
// to you as normal.
$("#select_course").change(function(e) {
var course_id = $(this).val();
alert(course_id);
});
}
};
});
Console error
