Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing text to a TXT file using javascript

Status
Not open for further replies.

javarookie

Programmer
Jul 19, 2002
2
CA
Hi, everyone. I need to write text to a TXT file. I'm running this script:

<script>
f=new File('c:\test.txt');
status=f.open('w');
f.write('test');
</script>

and I get an error: 'File' undefined.

What am I doing wrong? I got the example out of the book.
 
As far as I know you can't write to files... (at least not to the user's harddrive) It's not a lie if YOU believe it ;-)
 
Not knowing the name of the file you're trying to do this from, it appears that you're mixing Windows Scripting Host and HTML scripting, and that can't be done. If this in in an HTML page, you're limited to what HTML and Javascript allows. If this is a Windows Scriping Host file, then you'll need to declare the language in your script tag, and then instantiate the appropriate objects before you can write to a file. But the 2 don't mix. Windows Scripting Host is like batch files that are grown up, but a totally different subject from client-side scripting for web pages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top