www.webdeveloper.com
Results 1 to 3 of 3

Thread: read from txt

  1. #1
    Join Date
    May 2009
    Posts
    29

    read from txt

    Is this possible..

    When my HTA is opened is it possible to have one input text value be a specific line of a txt file

    say this is my script

    Code:
    <input type="text" id="firstone">
    and here is my txt file

    1
    2
    3
    4
    5
    6

    Is there a way to tell the script to open the text file and read the third line and make firstone.value="third line of something.txt"
    Last edited by dumbestcrayon; 07-08-2009 at 03:08 PM.

  2. #2
    Join Date
    Oct 2007
    Location
    Western Massachusetts, USA
    Posts
    387
    It is hard. I know what you are trying to do and I've tried it before. The best way I can think of is using displayarea.document.location = "text/file.txt"; where displayarea is the id of a hidden iframe. Then reading displayarea.innerHTML or something similar. I forgot the exact way of doing it. Then you do stringoftextfile.split("\n") or stringoftextfile.split("\r\n") i believe. then you can set the returned value of the split in a variable, and then access line 3 from thenewvariable[2]

  3. #3
    Join Date
    Jul 2009
    Posts
    48
    try

    Code:
    <script type="text/javascript">
    function getText()
    {
    	var doc = document.getElementById('firstone');
    
    	var SFSO = new ActiveXObject("Scripting.FileSystemObject");
    
    	var FSOF = SFSO.OpenTextFile("Textfile1.txt", 1);
    
    		doc.value = FSOF.ReadLine(3);
    }
    </script>
    Last edited by monkee98; 07-09-2009 at 08:01 AM. Reason: forgot to add something AGAIN!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles