Chapter 13: The Nuts and Bolts of JavaScript PDF Print E-mail
Sections - Part IV: Integrating Scripts with (X)HTML

A lot of good "canned JavaScript" is available for free on the Web; you know what we mean -- scripts written by someone else that you simply copy and paste into your HTML page. But as good as canned scripts can be, copy-and-paste goes only so far. Sooner or later, you're going to encounter unique needs that can't be fulfilled with a free script.

Canned JavaScript is much like canned Spam (the meat product, not the e-mail affliction): Great for convenience, but you probably don't want to make it an exclusive diet. Instead, knowing how to script -- or at least how to tweak a prewritten script -- is as important as knowing how to fix some good ol' fashioned home cooking.

In this chapter, you "open the can" of the JavaScript language and have a look at what's inside. (Don't worry; you won't encounter any meaty pink substances along the way.) You discover how to plug scripts into your pages, how to bundle your scripts into external JavaScript files to save time and effort, and how the nuts and bolts of the JavaScript language work. Finally, at the end of this chapter, we point you to good sources of additional information about JavaScript. These will come in handy as your scripting needs advance.

 

Page 224, Listing 13-1: Header script (display view) (code view)
Note that you may need to load the display view once to get it to work properly. On at least one of our test machines, it worked this way (load once, then try again, and everything works fine)

Page 226, Listing 13-2: External script reference (display view) (code view)

Page 227, Listing 13-3: An external JavaScript file (display view) (code view)

Page 236, Figure 13-1: Confirming an action (display view) (code view)
(Note that the "display view" version of this file won't validate because of the way it uses markup in the JavaScript itself. This is OK.)

Page 237, Listing 13-4 and Figure 13-2: A "for" loop (display view) (code view)
Note that the code in listing 13-4 won't validate at validator.w3.org because of the way it uses reserved markup (<h3>...</h3>) and characters "<" in the JavaScript code itself. You can visit jslint at www.jslint.com to check the Javascript portion, and validate the code without the script block, if you like.

Page 238, Listing 13-5: A while loop (display view) (code view)

Page 240, Listing 13-6, Figure 13-3: Calling a function (display view) (code view)

 

.ZIP file of all code samples from this chapter (10kb) 



Share this page!
Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!
Last Updated on Monday, 30 June 2008 11:41
 
Chapter Resources
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
Chapter 18
Chapter 19
Chapter 20
Chapter 21
Chapter 22
Chapter 23
Feedback - send us a message
Featured Links:
Banner
Visit co-author
Ed Tittel's web site!
Visit co-author
Jeff Noble's web site!
Conquest Media
Web page layout and
hosting provided by
SheTech and Company. the power of the web. http://www.shetech.com