Form data to text file or cookie

e_dawg

Storage Freak
Joined
Jul 19, 2002
Messages
1,903
Location
Toronto-ish, Canada
A question for you web developers out there...

How might one capture data from a form for logging purposes (e.g., tracking who signed-in to an intranet page by capturing the username from the username field) without the benefit of server-side scripting or SQL (using only client-side JScript)?

All I need is a text file, but it appears to be impossible.

I found a couple links that give examples using cookies instead of txt files, but no cigar:

http://codepunk.hardwar.org.uk/ajs27.htm

http://www.javascript-page.com/stinfo.html

The first link's code doesn't even appear to write a cookie. At least, I can't find any cookie from which to read. The second link's code seems able to create a cookie, but it has all this extra junk in it and overwrites any existing data on the cookie the next time the form is filled out.

Will, Doug? Someone must know how to do this supposedly simple task...
 

Will Rickards WT

Learning Storage Performance
Joined
Jun 19, 2002
Messages
433
Location
Pennsylvania, USA
Website
www.willrickards.net
You can only have one name/value pair in a cookie.
So to store a tracking list of the last ten users, you either need ten different names or a method of storing all ten in on value.
The javascript expression document.cookie contains all the cookie name/value pairs from all the cookies separated by semi-colons.

here is an example I whipped up... okay it took me a couple of hours.
I've never really used cookies that much.
 

e_dawg

Storage Freak
Joined
Jul 19, 2002
Messages
1,903
Location
Toronto-ish, Canada
Perfect. That was exactly what I was looking for. Thank you.

BTW, that was some nice JavaScript kung-fu, Will. I dub thee 'Cookie Monster'. ;)

So I guess one cannot simply write to a .txt file without including the path, expiry time, and all associated crap that a cookie entails?
 

Will Rickards WT

Learning Storage Performance
Joined
Jun 19, 2002
Messages
433
Location
Pennsylvania, USA
Website
www.willrickards.net
So I guess one cannot simply write to a .txt file without including the path, expiry time, and all associated crap that a cookie entails?

Well those are all required parts of the cookie.
If you don't include an expire timestamp, it is a this session only cookie.
You never see them when you read a cookie through javascript.
If you are reading the cookies from another program or through notepad, then you see them.

Writing to a text file on the client is another matter, and is generally not available in standard javascript. If it is an IE only type thing on a windows box then maybe you could use some of IE's capabilities to do it.
 
Top