954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Capturing data from txt file using JavaScript/HTML

I have successfully converted my .tiff file to a text file. This was a major step. My issue now that i am facing is "capturing" pertinent data. I am attempting to do this by running a JavaScript to create an HTML file from the .txt file. I am having trouble figuring out how I am going to pass the argument of a .txt file and embedding it into the HTML page.

Thoughts? Anyone? Bueller? Bueller?

dano

javadano
Newbie Poster
1 post since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

JavaScript cannot read a text file. You need to use server side code, such as ASP.NET or PHP, to process a file and render it to HTML.

However, you can store large text strings as JavaScript variables, and use the JavaScript document.write() method to write HTML strings.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Not sure if this will help but a friend wrote some kind of script (.js, .class) or something of that nature to do just what you are wanting. I'll try to send him here to help you out! It was called awrite.js or jwrite.js. I know he had posted it on some java search site, just not sure which one. Once again i'll try to send him here to help you out! In the mean time try a search engine and put in awrite or jwrite. You might be able to find it on the net!

LowelG
Newbie Poster
5 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

I thought, Javascript can not work with FSO. It's good to see this article.

Ryan

ryansmith
Newbie Poster
5 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

The only way to capture or embed .txt file into (x)HTML document, is to use AJAX. Just let me know if you need some example over this thing.

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

What about JQuery?? jQuery Documentation: http://docs.jquery.com/Ajax/load#urldatacallback
If not maybe try this code:

/*For safety reasons I would only allow the PHP file to determine the location of the file...if you want the ability to pick your file just post and I will modify my code*/
$file = "test.txt"
//Test if file exists
if(file_exists($file))
{
    //Open the file in read mode
    $fp = fopen($file, "r") or die("Error: Cannot open file");
   //Cycle through file
   while(!feof($fp))
   {
      //Return the file for AJAX to use
      echo fgets($fp);
   }
}
else { die("Error: Cannot find file"); }
FlashCreations
Posting Whiz
395 posts since Sep 2008
Reputation Points: 47
Solved Threads: 47
 

Don't bust yourself guys. Original post was Dec 2004!!!

Airshow

Airshow
WiFi Lounge Lizard
Moderator
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
 

Oh wow I didn't realize that this thread was that old. Now that I think about it....was jQuery even around back then?

FlashCreations
Posting Whiz
395 posts since Sep 2008
Reputation Points: 47
Solved Threads: 47
 
Oh wow I didn't realize that this thread was that old. Now that I think about it....was jQuery even around back then?


Good point FlashC. I think not http://docs.jquery.com/History_of_jQuery .

Airshow

Airshow
WiFi Lounge Lizard
Moderator
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
 

Hi flash,

JQuery is made for shorthand ellaboration of Javascript lines and simplifies the way you write your programs.
And about that documentation that you've provided still uses AJAX Technology. If you will just take a good look over its frameworks, you'll see that all parts of it, is created by the method's, and properties of the Javascript language.

And also if he wants this with PHP, then im sure this query wouldn't be here in the first place.

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 
<html>

<head><title>DOC</title>

<script language="JavaScript">

<!--//

function loadworddoc(){

var doc = new ActiveXObject("Word.Application"); // creates the word object

doc.Visible=false; // doesn't display Word window

doc.Documents.Open("F:\\Users\\Gaurav Srivastava\\Desktop\\Pendrive Backup\\Test.txt"); // specify path to

document


//copy the content from my word document and throw it into my variable

var txt;

txt = doc.Documents("F:\\Users\\Gaurav Srivastava\\Desktop\\Pendrive Backup\\Test.txt").Content;

document.all.myarea.value = txt;

doc.quit(0); // quit word (very important or you'll quickly chew up memory!)

}

//-->

</script>

</head>

<body>

<p><input type=button onClick="loadworddoc();" value="Load">

<p><textarea name=myarea cols=100 rows=25>nothing here yet</textarea>

</body>

</html>
iGaurav
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

WHY WHY??? YOU ARE NOT ENOUGH !!!!!!!!!!!!!!

http://www.alecjacobson.com/weblog/?p=1645

azzhey
Newbie Poster
1 post since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You