1. Post #1
    Dennab
    October 2007
    2,399 Posts
    I have the following little script for a website which creates a txt file, it overwrites the old .txt file upon re-submission is it possible to get the script to read the already existing file, remember it and add whatever is in the text fields to the end of the txt file?

    Code:
    <script language="javascript">
    function Writedata()
    {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var write_id;
    write_id = document.getElementById('write_id').value ;
    alert('The data has been written to \n' + write_id);
    var s = fso.CreateTextFile(write_id, true);
    
    s.WriteLine(document.getElementById('name_id').value);
    s.WriteLine(document.getElementById('year_id').value);
    s.WriteLine(document.getElementById('sept_id').value);
    s.WriteLine(document.getElementById('points_id').value);
    									
    s.Close();
    }
    </script>

  2. Post #2
    Gold Member
    ZeekyHBomb's Avatar
    June 2006
    3,577 Posts
    Code:
    var s = fso.OpenTextFile(write_id, ForAppending, true);
    should do the trick.

  3. Post #3
    Dennab
    October 2007
    2,399 Posts
    Thanks for the quick reply, Have a cookie.

    Edited:

    ok your fixes work, but now I have somthing else I need
    Code:
    <script language="javascript">
    function Writedata()
    {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var write_id;
    write_id = document.getElementById('write_id').value ;
    alert('The data has been written to \n' + write_id);
    var s = fso.OpenTextFile(write_id, 8, true, 0);
    
    s.WriteLine(document.getElementById('1stname_id').value);
    s.WriteLine(document.getElementById('2ndname_id').value);
    s.WriteLine(document.getElementById('year_id').value);
    s.WriteLine(document.getElementById('sept_id').value);
    s.WriteLine(document.getElementById('points_id').value);								
    s.Close();
    }
    </script>
    I need it to output all the text on 1 line with a gap between each piece of data...
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Friendly Friendly x 1 (list)

  4. Post #4
    Senney's Avatar
    June 2007
    258 Posts
    Thanks for the quick reply, Have a cookie.

    Edited:

    ok your fixes work, but now I have somthing else I need
    Code:
    <script language="javascript">
    function Writedata()
    {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var write_id;
    write_id = document.getElementById('write_id').value ;
    alert('The data has been written to \n' + write_id);
    var s = fso.OpenTextFile(write_id, 8, true, 0);
    
    s.WriteLine(document.getElementById('1stname_id').value);
    s.WriteLine(document.getElementById('2ndname_id').value);
    s.WriteLine(document.getElementById('year_id').value);
    s.WriteLine(document.getElementById('sept_id').value);
    s.WriteLine(document.getElementById('points_id').value);								
    s.Close();
    }
    </script>
    I need it to output all the text on 1 line with a gap between each piece of data...
    Code:
    var myWriteString = document.getElementById('1stname_id').value + " " + document.getElementById('2ndname_id').value + " " + ... and so on;
    s.WriteLine(myWriteString);
    My javascript is terrible, but i'm sure the point gets across.

  5. Post #5
    Dennab
    October 2007
    2,399 Posts
    Ah thanks a lot, this is an alternative to a SQL server, couldnt be arsed setting it up

  6. Post #6
    Dennab
    October 2007
    2,399 Posts
    is it possible for a symilar script to open a txt file and save it to a variable or string, then read the string or variable out?

  7. Post #7
    Gold Member
    ZeekyHBomb's Avatar
    June 2006
    3,577 Posts

  8. Post #8
    Dennab
    October 2007
    2,399 Posts
    I have been googleing for the past 3 hours, havnt found a thing usefull.

  9. Post #9
    Gold Member
    ZeekyHBomb's Avatar
    June 2006
    3,577 Posts
    I simply searched "Scripting.FileSystemObject", took the first link (form microsoft) and clicked on "Reference", then "FileSystemObject Methods" and there are 3 different methods for reading files.
    That's the same way I found out about how to append instead of override stuff in a file btw.

  10. Post #10

    February 2007
    177 Posts
    I would use perl for something like this.
    Code:
    open my $FILE, '+>>', 'thefile.txt'; # open thefile.txt in read/write/append mode
    my @entries = <$FILE>; # now the array @entries contains each line of the file, one element per line
    # do stuff with @entries...

  11. Post #11
    Dennab
    October 2007
    2,399 Posts
    well the reason I use javascript is I actualy have some understanding of it, anything else just goes over my head.

    all I have to now is get the bit working that checks each line for the word you typed in and update it with the newly entered data....

    is there any command that reads the Nth word in a row?