Results 1 to 4 of 4

Thread: writing to a file on server using js

  1. #1
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default writing to a file on server using js

    Hi All,
    I have a javascript file thru which I write some text on the webpage - something using the below to display on the page.

    var t = document.getElementById('foo');
    var tr = t.appendChild(document.createElement('tr'));
    tr.appendChild(document.createElement('td')).innerHTML = "NYY";
    tr.appendChild(document.createElement('td')).innerHTML = win;
    tr.appendChild(document.createElement('td')).innerHTML = loss;

    how ever I would need to write the above on a file on a txt file server side. The txt file will be

    NYY 10 3

    I have completed all the programming in javascript, but was not too sure how to use the write statement so that above when written on the page, is also written on a file in my webpage. Any code insights will be very very useful as I am working on a deadline.

    Thanks for your time and help in advance!!!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Javascript cannot do this. Use PHP or other server side code if available.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thank you!!!

    can i embed php or any server side code in javascript? since i already have finished the programming in javascript, do i need to rewrite it in php/any other server side?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You can arrange for your javascript to submit a form (most likely to a database), which if (both form and database are) properly setup will invoke the server side code and save your values. However, it might be better to approach it entirely from the server side, having your user submit the form to reload the page with the new values to/from the server, page, and the record file.

    One great advantage there is that no javascript is required on the user's part. This may or may not be important to you, but will make your page more accessible.

    Unfortunately I'm not so up on PHP and other server side coding, but I do know it can be done. If you do have PHP, check in the PHP forum for help with the details.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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