|
Lesson One | |
Like other programming languages, JavaScript has its' own rules and techniques. However, JavaScript needs HTML to function because it is a scripting language. Instead of creating programs, you will be creating enhanced Web pages. You must also remember, JavaScript is also an object-oriented language. As with many other languages,JavaScript also has objects, statements, and methods.
You begin with the opening tag <SCRIPT LANGUAGE="JavaScript">. You can use the same tags if you are using any other scripting language such as VBScript. This tag tells the browser that you are going to be programming in JavaScript. Notice the image to the left shows the version number "1.2". You only need to specify a version number if it's relating to a specific function that is not supported by more primative versions. Most of the time, you can omit the version number and your program will run just fine. Some of the older browsers can't read these higher versions of JavaScript or VBScript. This half of the program was put in the <HEAD> of the document. Between this tag and the corresponding </SCRIPT> is where you place your statements. The first statements are the document.write() and document.writeln(). document.writeln() can only be used with the HTML <PRE> tags for the simple reason that it adds carriage return which only <PRE> tags recognize. Some programs can be accessed from a source file. You would add a souce file by typing SRC="c:\jscript\sourcefile.js" within the opening <SCRIPT> tag at the end of the tag. This not only makes your document more neat in appearance, it makes it easier for other programs to access the same program, and it hides the actual code so that other people cannot see it. You can use either form, however, if you use a source file in the same <SCRIPT> block as an embedded program, the embedded program will be ignored. Objects, as well as other features of JavaScript, are case sensitive. So, if you write: If you need to comment on something to remind you of what the reason is for your variables, functions, objects, or events, you can specify them as such: // This represents a single line comment. /* You can also use the block version as a line comment. */ So, to sum things up, JavaScript statements can be added to HTML using <SCRIPT>...</SCRIPT> tags. LANGUAGE is the attribute you add to the <SCRIPT> tag when specifying what scripting language you're using. The Document object represents the content of a browser's window. It is a good idea to place much of your JavaScript in the <HEAD> section of the HTML document so it can be rendered before the <BODY> section Question: That seems too simple. If that's all there is to JavaScript, why not just learn HTML? Answer: Because, like programming languages, JavaScript requires variables, functions, objects, and events. This is what we will be learning next. |
|
If you have a questions about any of the lessons, feel free to ask. |