Click to See Complete Forum and Search --> : take from txt file


vinsa
02-14-2004, 12:31 PM
Hi,
first sorry for my english.
Can someone help me with this.
I use my page only offline
on my hard disk. I need javascript who
write (when the page load) in:
cell1 -> John
cell3 -> Smith
cell7 -> Frank
cell9 -> White
textarea t1 -> Dave
textarea t2 -> Jones

,and when I click over cell1 to copy John in
textarea t3. This script must take these names
from data.txt file.

=====My source===============
<html>
<head>
<title>table</title>

<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="data.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>

</head>
<body>
Table<br>

<table width="550" border="1" cellpadding="03" cellspacing="0"><tbody>

<tr>
<td>First name</td>
<td>&nbsp;</td>
<td>Last name</td>
</tr>

<tr>
<td id="cell1"></td>
<td>&nbsp;</td>
<td id="cell3"></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td id="cell7"></td>
<td>&nbsp;</td>
<td id="cell9"></td>
</tr>

</tbody></table> <br>

t1<input type="text" id="t1" size="45"> <br>
t2<input type="text" name="t2" size="45"><br>
<br><br>
t3<input type="text" name="t3" size="45">

</body>
</html>
==========END of my source===================

The contents of data.txt file:
First;Last
John;Smith
Frank;White
Dave;Jones
Daniel;Hamrick

Fang
02-14-2004, 01:13 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>ActiveX text loader</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
//<![CDATA[
<!--
function InsertNames() {
selectlist.recordset.MoveFirst();
document.getElementById('cell1').innerHTML=selectlist.recordset("First");
document.getElementById('cell3').innerHTML=selectlist.recordset("Last");
selectlist.recordset.MoveNext();
document.getElementById('cell7').innerHTML=selectlist.recordset("First");
document.getElementById('cell9').innerHTML=selectlist.recordset("Last");
selectlist.recordset.MoveNext();
document.getElementById('t1').value=selectlist.recordset("First");
document.getElementById('t2').value=selectlist.recordset("Last");
selectlist.recordset.MoveNext();
}
//-->
//]]>
</script>
</head>
<body onload="InsertNames();">
<p><object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="data.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>
Table<br>
</p>
<table width="550" border="1" cellpadding="3" cellspacing="0">
<tbody>

<tr>
<td>First name</td>
<td> </td>
<td>Last name</td>
</tr>

<tr>
<td id="cell1" onclick="document.getElementById('t3').value=this.innerHTML;"></td>
<td> </td>
<td id="cell3"></td>
</tr>

<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>

<tr>
<td id="cell7"></td>
<td> </td>
<td id="cell9"></td>
</tr>

</tbody></table>

<form action="#" name="myform">
<p>
t1<input type="text" id="t1" size="45"> <br>
t2<input type="text" id="t2" name="t2" size="45"><br><br><br>
t3<input type="text" id="t3" name="t3" size="45">
</p>
</form>
</body>
</html>

vinsa
02-15-2004, 05:11 AM
Thank you very much, it work.
Now I see, that you use

selectlist.recordset.MoveNext();

to take the names of every next row
and to show them in the table.
But if I want to skip some rows?
What I must to use then?
Example, I have ten rows and want
to show in cell1 and cell3 the names
in seventh row (Herrman;Brown).
Can you do that?

First;Last
John;Smith
Frank;White
Dave;Jones
Daniel;Hamrick
Mike;Bing
Ross;Gelar
Herrman;Brown
Linda;Hoffman
Jack;London
Vin;Diesel

Fang
02-15-2004, 05:57 AM
You have to iterate through the list and pick out the required record:

selectlist.recordset.MoveFirst();
for(var i=1; i<=selectlist.recordset.AbsolutePosition; i++) {
if(i==7) {SomeElementValue=selectlist.recordset("First");}
selectlist.recordset.MoveNext();
}

vinsa
02-15-2004, 09:20 AM
HI Fang,
I don't understand how exactly I must to include the last in the script. Could you explane me?
I don't understand this technology very well and can't modify the script. Can you tell me from where can I find more info?

Fang
02-15-2004, 11:17 AM
Place it in function InsertNames.
Data binding (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndude/html/dude1103.asp)

vinsa
02-19-2004, 10:14 AM
Hi Fang,
can you change this script so as to select random name from text file? I try but I can't

Fang
02-19-2004, 12:45 PM
Try:
function InsertNames() {
var RandomName=Math.floor(Math.random() * selectlist.recordset.RecordCount);
selectlist.recordset.MoveFirst();
for(var i=1; i<selectlist.recordset.RecordCount; i++) {
if(i==RandomName) {
document.getElementById('cell1').innerHTML=selectlist.recordset("First");
document.getElementById('cell3').innerHTML=selectlist.recordset("Last");
}
selectlist.recordset.MoveNext();
}
}

vinsa
02-19-2004, 02:29 PM
Thank you Fang :)) You are the best