View Full Version : writing to a file on server using js

11-12-2008, 02:35 AM
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!!!

11-12-2008, 03:58 AM
Javascript cannot do this. Use PHP or other server side code if available.

11-12-2008, 03:40 PM
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?

11-12-2008, 03:48 PM
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.