Jump to content

How to store the user input in the form of transcripts in Javascript?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
swathisambaraj

swathisambaraj

    Newbie

  • Members
  • Pip
  • 4 posts
Hi,

I want to store the input given by the user into some file and view it later..
For example:
Referring to this simple code..
<html>

<body>


<form action="form_action.asp" method="get">

First name: <input type="text" name="fname" /><br />

Last name: <input type="text" name="lname" /><br />

<input type="submit" value="Submit" />

</form>


</body>

</html>

In this example when the user hits the submit button, i want to store the first name and lastname in some file in my computer and view it later. Do i need to use backend for this to maintain the Database.. (OR) Are there any Emport/import options in Javascript...

How do i do this ?

Please let me know... Your help will be greatly appreciated!!
Thanks in advance.

Awaiting your response,
Swathi

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
By default there isn't anything in JS to store data in a file, you'd need to use a server side language such as ASP or PHP. If you can run PHP on your server and decide to do it I can write the code here if you want me to!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
swathisambaraj

swathisambaraj

    Newbie

  • Members
  • Pip
  • 4 posts
Thank u! Please do write the code since i am completely unaware of ASP and PHP,..
Can we do this in python?

#4
NastyDevil

NastyDevil

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
I would also advice you to look into a database storage. As Nullworm said you can use PHP to store it in a file but depending on what you are looking to do a database might be able to simplify the process. It shouldnt be too hard to code, good luck.

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
You'd need to enable Python on your server which requires root access, so I'm not sure you can do it in that. If you want to do what you originally stated to store it in a file, you could use this simple script in PHP:

<?php


if(isset($_POST['fname'])) {

    // grab data from form

    $fname = $_POST['fname'];

    $lname = $_POST['lname'];


    // open file handle to append

    $fp = fopen("log.txt",  "a");  


    // write the slug to log.txt:

    fputs($fp, "First name: $fname, Last name: $lname\r\n");

    fclose($fp);  

}


?>

You would name this process.php and plug it into your form:

<form action="process.php" method="POST">

...

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
swathisambaraj

swathisambaraj

    Newbie

  • Members
  • Pip
  • 4 posts
Thank u!!

#7
leeyo

leeyo

    Newbie

  • Members
  • PipPip
  • 12 posts
javascript is enouth.you don't need to use server language as asp and php.
you can test the codes below.
to write a file:
<script language="JavaScript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
fs=new XMLHttpRequest();
}
else
{// code for IE6, IE5
fs=new ActiveXObject("Scripting.FileSystemObject");
}
var file=fs.CreateTextFile("c:\\test.txt",true);
file.WriteLine("This is test text.");
file.Close();
</script>

to read a file:
<script language="JavaScript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
fs=new XMLHttpRequest();
}
else
{// code for IE6, IE5
fs=new ActiveXObject("Scripting.FileSystemObject");
}
var file=fs.OpenTextFile("c:\\test.txt");
alert(file.AtEndOfLine?"file is null.":file.ReadLine());
file.Close();
</script>

Edited by leeyo, 23 June 2010 - 12:06 AM.
type wrong.