15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

dataFld<br />

dataFormatAs<br />

dataSrc<br />

elementObject.dataFld<br />

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

Compatibility ✓ ✓ ✓<br />

Example<br />

Listing 15-8 is a simple document that has two TDC objects associated with it.<br />

The external files are different formats of the U.S. Bill of Rights document. One file is<br />

a traditional, tab-delimited data file consisting of only two records. The first record<br />

is a tab-delimited sequence of field names (named “Article1”, “Article2”, and<br />

so on); the second record is a tab-delimited sequence of article content defined in<br />

HTML:<br />

ARTICLE ICongress shall make...<br />

The second file is a raw text file consisting of the full Bill of Rights with no HTML<br />

formatting attached.<br />

When you load Listing 15-8, only the first article of the Bill of Rights appears in a<br />

blue-bordered box. Buttons enable you to navigate to the previous and next articles<br />

in the series. Because the data source is a traditional, tab-delimited file, the<br />

nextField() and prevField() functions calculate the name of the next source<br />

field and assign the new value to the dataFld property. All of the data is already in<br />

the browser after the page loads, so cycling through the records is as fast as the<br />

browser can reflow the page to accommodate the new content.<br />

Listing 15-8: Changing dataFld and dataSrc Properties<br />

<br />

<br />

Data Binding<br />

<br />

#display {width:500px; border:10px ridge blue; padding:20px}<br />

.hiddenControl {display:none}<br />

<br />

<br />

function nextField() {<br />

var elem = document.all.display<br />

var fieldName = elem.dataFld<br />

var currFieldNum = parseInt(fieldName.substring(7, fieldName.length),10)<br />

currFieldNum = (currFieldNum == 10) ? 1 : ++currFieldNum<br />

elem.dataFld = “Article” + currFieldNum<br />

}

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

Saved successfully!

Ooh no, something went wrong!