Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

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

user input

  • Please log in to reply
6 replies to this topic

#1 swathisambaraj

swathisambaraj

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 17 June 2010 - 09:23 AM

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
  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 17 June 2010 - 09:30 AM

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!
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 swathisambaraj

swathisambaraj

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 17 June 2010 - 10:39 AM

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

#4 NastyDevil

NastyDevil

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 90 posts

Posted 17 June 2010 - 10:48 AM

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.
  • 0

#5 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 17 June 2010 - 10:56 AM

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">
...

  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#6 swathisambaraj

swathisambaraj

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 17 June 2010 - 11:27 AM

Thank u!!
  • 0

#7 leeyo

leeyo

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 23 June 2010 - 12:05 AM

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.

  • 0





Also tagged with one or more of these keywords: user input

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download