Skip to main content

How to use the Javascript template in Moodles Database Activity Module

There is a javascript template located in the Moodle Database Activity Module so instructors can recognize when students click buttons or hover over textareas, and other such basic functionality.

In the attached file, you can see several examples of working javascript.
The first function called fillBoxes() will make the input fields = “Hello World” as you can see in the picture.

document.getElementById(‘field_482_0’).value = “Hello”

This line searches the document for an element with the id=“field_482_0” and changes its value to “Hello”.
The getElementById function requires a string parameter to work, in this case being “field_482_0”.
Most HTML document elements, whether a button, a picture, a string, have an id/class/name that you can fill such a parameter with. You can investigate this by right clicking the website and clicking “Inspect Element” (Chrome/FireFox) or “View Source” (Internet Explorer).

When we inspect the Moodle database website, we see in the picture that the first input field by Url: has the id=‘field_482_0’. Having found the element, we change the value to “Hello”