Welcome to CTN 162
The purpose of this class is to show you, as a Web designer or Web developer, how to use JavaScript to help you create interactiveWeb sites.
Starting place:
Before you begin learning about JavaScript, it helps to have a basic knowledge of:
- HTML (the basics of using tags and attributes, the difference between the <head> and <body> sections)
- Text editors (Notepad, SimpleText, TextPad, etc.)
- Web browsers (Microsoft Internet Explorer, Mozilla/Firefox/Netscape, Opera, Safari, etc.)
- The different versions of JavaScript
- JavaScript 1.5 is supported in the latest browsers
- JavaScript 1.3 was supported in MSIE 5/Netscape 4.5
- JavaScript 1.2 was supported in MSIE 4/Netscape 4
- JavaScript 1.0/1.1 was supported in MSIE 3/Netscape 3
- JScript is the version of JavaScript that MSIE uses: it has additional features because it's implemented as a Windows script engine
- ECMAScript is the international standard name and specification for the JavaScript language.
JavaScript is not Java
The only thing JavaScript and Java have in common is the letters J-A-V-A. Java is a full programming language. It has to be compiled into machine language before a program (often known as a Java applet) can be executed. Java is more powerful and more complex.
JavaScript doesn't need a compiler, it is interpreted by a scripting engine (interpreter) in the user's Web browser. Scripting languages such as JavaScript and Perl are run through an interpreter, rather than being compiled. JavaScript is more lenient in a number of areas, such as syntax.
Widely-used terminology distinguishes object-oriented programming from object-based. The former is held to include inheritance, while the latter does not. Strictly speaking, JavaScript is not a true Object Oriented language as C++ or Java but rather an Object Based language.
Stuff that might give you a headache now but should make sense before the end of the quarter
Object-based
Object-based means that JavaScript uses items called objects. The objects in JavaScript are just general objects, they are not class-based--there's no distinction between a class and an instance.
Client-side
JavaScript runs in the user's client software, e.g. their Web browser, rather than on the Web server of the site serving the page.
A server-side language gets information from the Web page or Web browser and sends it to a program running on the Web server, which does something with the information and sends it back to the browser. This gives the server-side programmer certain options beyond what they'd get client-side, such as saving information on the server for later use, or using the information to update a Web page and display the saved, updated results.
A client-side language runs directly through the client being used by the viewer. (With JavaScript, that client is usually a Web browser.) It doesn't need the extra step of sending and retrieving information from the Web server. The browser reads and interprets the code and can give the user the results without first getting information from the server. This is quicker than server-side, but it can't save files or update information on the server.
A client-side language is ideal for validating information before it's sent to the server (i.e., did you include your credit card number on the form?). JavaScript can do other things that don't require communication back to the server, such as opening a new window with specific dimensions, placing it on the screen, and making the choice of whether or not to include certain features (scrollbar, toolbar, status bar, etc.).
Scripting Language
Before you can run a program wriiten in a regular programming language, you have to run it through a compiler to check for syntax errors and to convert it into the language a computer can understand. A scriping language is interpreted on-the-fly as it is loaded into the client. Unfortunately, with JavaScript that leaves the error-handling in the hands of the browser, and coding errors can cause some interesting problems. Be sure to test your code in as many browsers as you can get your hands on.
Getting it together
JavaScript runs in the browser by being added into an existing HTML document.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>This page written by JavaScript</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<script language="JavaScript" type="text/JavaScript">
<!--
document.write("This text was written with JavaScript!");
//-->
</script>
</body>
</html>