This page contains information about the example scripts.
Back to the Book homepage.
The majority of the code examples in the book come from the example scripts. I've done my best to annotate these code examples with line numbers, so that you can easily find and study the complete code. You can download the ZIP file that contains the example scripts in .txt format, including the line numbers. If you want to print them, I advise you to select Landscape format.
The line numbering system is not perfect. I frequently made minor changes to the scripts while I was writing the book, and it was only in May, when I started on the final version, that I froze the example scripts so that I could start adding the line numbers to all code examples.
Unfortunately I made a few slight errors during this freezing. For instance, line 105 of Form Validation is spurious: it occurs between two lines with closing curly braces
}, and in general I never use an empty line in such a place. When I noticed this error, I had already annotated the majority of the example scripts and I didn't want to go through six chapters to check all Form Validation line references. Therefore the error has not been removed.
Besides, I'm absolutely certain I made a line numbering mistake somewhere in the book. I just haven't found the mistake(s) yet.
Below you find the eight example scripts, as well as links to the working version and the .txt version with line numbers. See the Introduction for a general description of the scripts.
The book contains three general comparisons of all the example scripts:
Line by line explanation.
This script operates in all my Blog pages to restrict comment length
<span>that shows the counter.
innerHTMLto insert the
<span>. Cooperation of
innerHTMLwith "pure" DOM methods.
How to use the script in your own sites.
This example script shares a page with Form Validation.
display: noneor remove form fields from document structure?
ifstatement on lines 77-81.
whileloop in lines 41-51.
ifstatement on lines 77-81 as an example of the use of
<tr>s that should be removed from the document. How I use that array.
This example script shares a page with Usable Forms.
validationattribute and why it's better not to use it.
validFormas an example of boolean variables.
reqsarray on lines 80-85 as an example of an array.
falsein line 105).
isRequired()function as an example of checking form fields.
This example script shares a page with Edit Style Sheet.
class="menutree"as a hook.
document.write()to add an extra style sheet.
This example script shares a page with Dropdown Menu.
switchblock on lines 74-86.
do/whileloop on lines 79-95.
assignStyles()function as an example of the
for instatement on lines 68-70.
findPosreturns an array.
<tr>equals one sandwich.
idas a hook.
createReadablePrice()as an example of the return value of a function.
thiskeyword and the event target.
<tr>as example of the short-distance document travel properties.
removeFromOrder()as examples of the use of
nodeValueon line 38.
addExtraButton()as an example of
removeExtraButton()as an example of
<tr>s to the
priceproperty vs. the HTML
Live version. I wrote the script for the ISP Wanadoo, but meanwhile it has changed its name to Orange; and the graphic design of the page has changed. The script still works, though.
sendRequestfunction as an example of nested functions and definition scope of variables.
Printable version survey.js
Printable version popup.js
addInput()from popup.js as an example of a function.
focus()in lines 59-63.
trackMain(), lines 34-37.
innerHTMLto show the popup warning text.