louisstephens Posted August 13, 2009 Share Posted August 13, 2009 As the title suggests, I am wanting to use javascript to create a new text file and write the data from a HTML form every time the "submit" button is pressed. I know how to do this in PHP, but I am pretty much "stuck" with using javascript. Quote Link to comment Share on other sites More sharing options...
trq Posted August 13, 2009 Share Posted August 13, 2009 The best you could do is write to a cookie. You don't have permission enough to write any other file on the client. Quote Link to comment Share on other sites More sharing options...
louisstephens Posted August 13, 2009 Author Share Posted August 13, 2009 Ah ok.. I am really just doing this for an Adobe Air app. Quote Link to comment Share on other sites More sharing options...
dmcdivitt Posted August 13, 2009 Share Posted August 13, 2009 Use the onclick event and submit the form, but on the server side do not write a page. Instead do the following in PHP: header("Content-disposition: attachment; filename="whatever.txt"); header("Content-type: document/text"); - echo your lines ending each with "\r\n"; return; This will cause a view/save dialog to appear at the client. Be sure and use return to kill the script so no additional output can occur such as an extra linefeed after the PHP close tag. Quote Link to comment Share on other sites More sharing options...
louisstephens Posted August 13, 2009 Author Share Posted August 13, 2009 So what you are saying is that I need an html file with the forms That sends it to a php file which will do all the work? Quote Link to comment Share on other sites More sharing options...
dmcdivitt Posted August 13, 2009 Share Posted August 13, 2009 Yes, but you can use one PHP file for all of it. When the script begins executing, check $_POST["button"] to see if it has a value. If yes, that means the page has already been rendered and someone clicked a button on the page. You can also use $_POST["usertext"] to obtain the text the user entered. You would then just stream a text file back out to the client and not output an HTML page. Otherwise, output the HTML page from your PHP script in the normal fashion, and when you output the page, be sure and include the form element, button, and text box. The action or URL of the form element should be the same PHP script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.