Learn JavaScript Lesson 2 : The Basics

This is our second article about using JavaScript in your templates. In this article we discuss where to put your code and some of the things that you must do to get to to run correctly.

There are two areas that we can put JavaScript code, the first is in the head section of your template.







We put code here normally if we have subroutines and functions that we need to reference in our page or when an event is triggered. The other place to put code is to put it in the Body of the page







If you put the code in the body then it will be executed when the page is loaded into the users browser. There is no limit to the number of lines of JavaScript you can add or the places that you add them. As you become more experienced with JavaScript you may find yourself writing the same routine over and over again. To save you from having to do this you can create .js files and then just reference them in your template.







If you do use this you should note that you don’t need to but the