Invoking Script

There are a number of ways to invoke a JavaScript function from within the body of an html page. The easiest method is to use a variant of the anchor tag. The anchor tag, <a>, is most commonly used to link to another html page

<a href=""> Go to WebPhysics! </a>

but it can also be used to send email, connect to an ftp server, or execute JavaScript. In order to execute a JavaScript function the http link is replaced with the JavaScript as follows:

<a href="JavaScript:initApplet(xDefault,yDefault)"> Problem 1.</a>

Clicking on the text bracketed by the <a> and </a> tags will execute the JavaScript function that was previously defined as initApplet (x,y). The script can be called a second time elsewhere on a page using different parameters

<a href="JavaScript:initApplet('8+4*t','0')">Problem 2.</a>

Notice that the first script uses the x and y variables defined in the head, while the second script makes use of two strings that are defined on the spot. Scripting techniques such as these make it possible for a Physlet to support many different types of problems and to change its behavior while the student is working through an exercise.