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:
Working version
Printable version
Line by line explanation.
This script operates in all my Blog pages to restrict comment length
<span> that shows the counter.innerHTML to insert the <span>. Cooperation of innerHTML with "pure" DOM methods.Working version
Printable version
How to use the script in your own sites.
This example script shares a page with Form Validation.
display: none or remove form fields from document structure?<tr>s!if statement on lines 77-81.while loop in lines 41-51.addEventSimple().this keyword.getElementsByTagName.if statement on lines 77-81 as an example of the use of nodeName.insertBefore().replaceChild().<tr>s that should be removed from the document. How I use that array. shift() and push().hiddenFormFieldPointers associative array.Working version
Printable version
This example script shares a page with Usable Forms.
validation attribute and why it's better not to use it.validForm as an example of boolean variables.switch block in isRequired().validationFunctions associative array.reqs array on lines 80-85 as an example of an array.true or false in line 105).isRequired() function as an example of checking form fields.style property.Working version
Printable version
This example script shares a page with Edit Style Sheet.
:hover or JavaScript?<ul>s.class="menutree" as a hook.document.write() to add an extra style sheet.Working version
Printable version
This example script shares a page with Dropdown Menu.
switch block on lines 74-86.do/while loop on lines 79-95.assignStyles() function as an example of the [] notation of JavaScript objects.for in statement on lines 68-70.findPos returns an array.Working version
Printable version
<tr> equals one sandwich.id as a hook.createReadablePrice() as an example of the return value of a function.price property.this keyword and the event target.<tr> as example of the short-distance document travel properties.moveToOrder() and removeFromOrder() as examples of the use of parentNode.nodeValue on line 38.addExtraButton() as an example of appendChild().removeExtraButton() as an example of removeChild().<tr>s to the <tbody>.price property vs. the HTML price attribute.removeButton().Working version
Printable version
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.
sendRequest function as an example of nested functions and definition scope of variables.speedText array.setWidth() function.sendRequest() function.catchData() function.Working version
Printable version survey.js
Printable version popup.js
This is the only example script that consists of two JavaScript files: survey.js for use in all pages of the host site; popup.js for use in the popup.
addInput() from popup.js as an example of a function.resizeTo() and focus()in lines 59-63.trackMain(), lines 34-37.addEventSimple().innerHTML to show the popup warning text.