
 |
| Corresponding text on pages 11-14. |
To set up a Javascript, within your html document write the following:<script language=javascript type=text/javascript>
<!-- hide script from older browsers
(This is where your actual script goes)
// end hiding script from older browsers -->
</script>
I would recommend copying this basic script setup and saving it into your exercises folder as scripttemplate or some such name. You can reuse it over and over again for each new script you write, substituting the script statements for the words in blue italic print.Like HTML, it is not crucial how many lines or spaces you skip when you write Javascript. You could write it all in a row on one line and continue on. I find it helpful in javascript to skip lines for each "section"(like above). Javascript is case sensitive. Some objects in Javascript are written in a specific case(upper or lower). Glance through pages 261-270 to view some examples of case specific terms. Be consistent when you write the rest of the script(I recommend lower case) and you'll never spend an hour debugging your code only to find out it was just a capital letter that fouled it up. Of less importance because we use Wordpad in this class, but never use curvy quote marks. Wordpad defaults to Courier New which uses straight quotes(' and ").
You can place your script in either the <head> of the document or the <body> of the document. More often than not you place the script in the <head>, but the general rule is this:
- <head>- Place the script in the head when any event other than the loading of the page causes the script to activate(ie. mouse action, typing by the user, etc.) The advantage of putting the script in the head is that it loads before the body starts to load, ensuring that your script is there when the user activates it.
- <body>- Place the script in the body when the activation event is simply the loading of the page.(occurs less often, but you will often place the script itself in the head and the user action(called "event handlers") in the body tag itself. For example, <body onmouseover="message()">.)
You can place as many scripts as you want to in an html document. You can combine all of your script statements that belong in the <head> section together in one script. You can also combine all of your script statements that belong in the <body> section together in one script.
>>Script Terminology
Index
Grading
Schedule
Photoshop
Styles
Resources
Exercises
Links