Javascript Handout (for CSCI 115 Final Exam)

Please note that this page is intended to show only the basic JavaScript features used in CSCI 115.

Basic Code Layout

<script>
// Global variables
. . .

// functions
. . .

function init()
{
    . . .
    // Event handlers
    . . .
}

window.onload = init;
</script>

Defining Event Handlers

Event handlers must be placed inside the braces for the init function.


document.getElementById("sourceId").onwhatever = function()
{
    document.getElementById("target1").style.color = "red";
    document.getElementById("target1").innerHTML = "new content";
    document.getElementById("target1").src = "new iamge file";
    . . .
}

Built-in Functions