↑
Main Page
window.onload
<object classid=”CLSID:333C7BC4-460F-11D0-BC04-0080C7055A83” id=”TextData”>
<param name=”DataURL” value=”Names.txt” />
<param name=”FieldDelim” value=”,” />
</object>
Lastly, if the file in question uses the first row as headers, you should set the
UseHeader
parameter to
true
, which doesn’t include the first row in the data values and also enables you to reference columns
by name as well as position:
<object classid=”CLSID:333C7BC4-460F-11D0-BC04-0080C7055A83” id=”TextData”>
<param name=”DataURL” value=”Names.txt” />
<param name=”FieldDelim” value=”,” />
<param name=”UseHeader” value=”true” />
</object>
This code says to load the tabular data control with the data in
Names.txt
that has a field delimiter of
“,”
and use the headers as a key for each column.
Here’s a sample
Names.txt
file:
first_name,last_name
Nicholas,Zakas
Michael,Smith
Joyce,Anderson
Benjamin,Johnson
Amy,Jones
The first column is named
first_name
, and the second column is named
last_name
. On each row,
commas, as indicated by using the
FieldDelim
parameter, separate the values.
The page’s
load
event does not fire until the tabular data control has fully loaded its data, so it’s safe to
use the
onload
event handler to determine when the data is available. At that point, you retrieve the
recordset created by accessing the
recordset
property of the control:
window.onload = function () {
oDataset = document.getElementById(“TextData”).recordset;
};
This code creates a global variable named
oDataset
that points to the recordset containing all the data.
You can iterate through the recordset by using the
moveFirst()
,
moveLast()
,
moveNext()
, and
movePrevious()
methods in combination with the
EOF
(end of file) and
BOF
(beginning of file) mark-
ers. For example, here’s a basic code outline to iterate through the recordset starting from the first record
and ending with the last:
oDataset.moveFirst();
while (!oDataset.EOF) {
//do something with the data here
oDataset.moveNext();
}
559
Interacting with Plugins
21_579088 ch18.qxd 3/28/05 11:43 AM Page 559
Free JavaScript Editor
Ajax Editor
©
→