views:

77

answers:

3

I'm writing a simple HTML+JavaScript app, intended to load from a local file and run in the user's browser. It will allow them to enter some text into a textarea... and must also allow them to save it!

So this is my problem: given that JavaScript doesn't have access to the local file system, how can I cause this text to be saved?

+1  A: 

Is your textbox in a form ? Is so, get its content in php and write it.

If not, get the content in javascript and do an Ajax call to a php script which will write it.

Your file will be written on server side, and not on client side.

Guillaume Lebourgeois
I want to use it on client side without the use of php, can you give me javascript to do so, suppose textbox id is "name"
You cannot do that because of security restrictions. You can either write a server-side script or use an XPCOM bindings in Firefox, for instance. Why do you need that at all?
floatless
i had created a web Examination Application and want to store user input data, thats why.......
+2  A: 

You should create a form using the form element on your HTML page. After that, create a server-side script (PHP, Ruby, Python) to process your form data. You can transfer the data via POST or GET request.

<form method="post" action="/process.php">
    <textarea name="text"></textarea>
    <button type="submit">Send data</button>
</form>

And process.php:

if (isset($_POST["text"]))
{
    file_put_contents("my_file.txt", $_POST["text"]);
}
floatless
A: 

As far as I know you can't use javascript or other client-side scripting language for security reasons so you have to use a server-side language like PHP, Ruby, Python etc... Generally speaking you have to create your HTML form and ad a button to send the data to your server so you can process it.

BTW you question is really incomplete. Maybe you can edit it and we can be more specific.

Example

<form method="post" action="/file.php">
    <textarea name="what_i_want_to_save"></textarea>
    <button type="submit">Submit</button>
</form>

In method you can use also get. Then in file.php you can do something following this link http://php.net/manual/en/function.fwrite.php if you want to use php.

dierre