15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

44 <strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to experiment with these<br />

two properties of the TEXTAREA object, which displays the output of evaluations<br />

and property listings. To begin, enter the following into the bottom one-line text<br />

field to list the properties of the body object:<br />

document.body<br />

This displays a long list of properties for the body object. Use the TEXTAREA’s<br />

scrollbar to page down a couple of times. Now enter the following property expression<br />

in the top one-line text field to see the scrollTop property of the output<br />

TEXTAREA after you scroll:<br />

document.all.output.scrollTop<br />

The result, some number, is now displayed in the output TEXTAREA. This means<br />

that the content of the output element was scrolled vertically. Click the Evaluate<br />

button once more. The result, 0, is a measure of the scrollTop property of the<br />

TEXTAREA that had only the previous result in it. There wasn’t enough content in<br />

the TEXTAREA to scroll, so the content was not scrolled at all. The scrollTop<br />

property, therefore, is zero. The scrollLeft property of the output is always zero<br />

because the TEXTAREA element is set to wrap any text that overflows the width of<br />

the element. No horizontal scrollbar appears in this case, and the scrollLeft<br />

property never changes.<br />

sourceIndex<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓<br />

Example<br />

While the operation of this property is straightforward, the sequence of elements<br />

exposed by the document.all property may not be. To that end, you can<br />

use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to experiment in IE4+ with<br />

the values that the sourceIndex property returns to see how the index values of<br />

the document.all collection follow the source code.<br />

To begin, reload The Evaluator. Enter the following statement in the top text box<br />

to set a preinitialized global variable:<br />

a = 0<br />

elementObject.sourceIndex<br />

When you evaluate this expression, a zero should appear in the Results box.<br />

Next, enter the following statement into the top text box:<br />

document.all[a].tagName + “ [“ + a++ + “]”<br />

There are a lot of plus signs in this statement, so be sure you enter it correctly. As<br />

you successively evaluate this statement (by repeatedly clicking the Evaluate button),<br />

the global variable (a) is incremented, thus enabling you to “walk through” the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!