/    Sign up×
Community /Pin to ProfileBookmark

take from txt file

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.
[COLOR=blue]
=====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===================
[/COLOR]
The contents of data.txt file:
[COLOR=red]First;Last
John;Smith
Frank;White
Dave;Jones
Daniel;Hamrick
[/COLOR]

to post a comment
JavaScript

8 Comments(s)

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

&lt;tr&gt;
&lt;td&gt;First name&lt;/td&gt;
&lt;td&gt; &lt;/td&gt;
&lt;td&gt;Last name&lt;/td&gt;
&lt;/tr&gt;

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

&lt;tr&gt;
&lt;td&gt; &lt;/td&gt;
&lt;td&gt; &lt;/td&gt;
&lt;td&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td id="cell7"&gt;&lt;/td&gt;
&lt;td&gt; &lt;/td&gt;
&lt;td id="cell9"&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;/tbody&gt;&lt;/table&gt;

&lt;form action="#" name="myform"&gt;
&lt;p&gt;
t1&lt;input type="text" id="t1" size="45"&gt; &lt;br&gt;
t2&lt;input type="text" id="t2" name="t2" size="45"&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
t3&lt;input type="text" id="t3" name="t3" size="45"&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@vinsaauthorFeb 15.2004 — Thank you very much, it work.

Now I see, that you use

[COLOR=blue]selectlist.recordset.MoveNext();[/COLOR]

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?

[COLOR=blue]

First;Last

John;Smith

Frank;White

Dave;Jones

Daniel;Hamrick

Mike;Bing

Ross;Gelar

Herrman;Brown

Linda;Hoffman

Jack;London

Vin;Diesel

[/COLOR]
Copy linkTweet thisAlerts:
@FangFeb 15.2004 — 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();

}
Copy linkTweet thisAlerts:
@vinsaauthorFeb 15.2004 — 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?
Copy linkTweet thisAlerts:
@FangFeb 15.2004 — Place it in function InsertNames.

[URL=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndude/html/dude1103.asp]Data binding[/URL]
Copy linkTweet thisAlerts:
@vinsaauthorFeb 19.2004 — Hi Fang,

can you change this script so as to select random name from text file? I try but I can't
Copy linkTweet thisAlerts:
@FangFeb 19.2004 — Try:
function InsertNames() {
var RandomName=Math.floor(Math.random() * selectlist.recordset.RecordCount);
selectlist.recordset.MoveFirst();
for(var i=1; i&lt;selectlist.recordset.RecordCount; i++) {
if(i==RandomName) {
document.getElementById('cell1').innerHTML=selectlist.recordset("First");
document.getElementById('cell3').innerHTML=selectlist.recordset("Last");
}
selectlist.recordset.MoveNext();
}
}
Copy linkTweet thisAlerts:
@vinsaauthorFeb 19.2004 — Thank you Fang ?) You are the best
×

Success!

Help @vinsa spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...