Scripting is another type of programming, but it's easier to learn, which is a plus. Scripts can be added to an HTML document using the <script> tag. The tag can appear within the <head> or <body> of the document. A script might be contained in a separate document that is called by the <script> tag (much as a linked style sheet is a separate document called by the <style> tag). A script might also be contained within the <script> tags in the HTML document itself. The decision is yours, based on how often you plan to use the script. If the script appears in only one page, incorporate the script into the document, as in the first of the following HTML samples. If the script appears on more than one page, make it a separate file so that you don't have to duplicate it, as in the second HTML sample. <script type="text/vbscript">enter your script here.</script> <script type="text/javascript" src="/books/1/174/1/html/2/http://www.myweb.com/scripts/myscript.jss"> </script> Although the src (source) attribute is only required when the script is contained in a separate file, the type attribute is always required. This attribute tells the browser which language the script is written in: text/javascript, text/vbscript, or text/tcl. If you are using the same scripting language throughout your HTML document, you can include a <meta> tag that defines the default script type for the entire document. The <meta> tag (as you learned in Lesson 3, "Adding Text and More") is placed inside the <head> tag and gives the browser information about the document. <meta http-equiv="Content-Script-Type" content="type"> What Can Scripting Do?The easy answer to this question is anything. If you look at some of the script collections on the Web, you find that people are using script for all kinds of thingsincluding adding table values, creating rollover effects, and even games. Tip
It is possible to associate a script with a certain event that occurs when the page appears on the browser. Figure 14.2 is an HTML page with some very simple JavaScript code that changes the background color of the page with the press of a button. Figure 14.2. Simple JavaScript code to change the background color with the onclick command.You might wonder where the code is because the <script> tag is empty. The code, in this case, is embedded in the <input> tag with the onclick command. The tag responds to each of the events shown in Table 14.2 and a few more.
Tip
The scope of this book does not allow for coverage of all these topics in any depth, but I hope you have some idea of the possibilities and can take the time to learn more on your own. Table 14.3 lists the HTML tags that were discussed in this lesson.
In this lesson, you've learned:
|