Forum Moderators: open

Message Too Old, No Replies

how to save data from html to a text file client side

is it possible in js to save data form html to txt?

         

eranfox

9:05 am on Jun 8, 2005 (gmt 0)

10+ Year Member



Hello Everybody,
I'm new to javascript but...
i don't know how to save data from html input boxes to a simple text file on the client side without using asp or php or cgi etc.

Thank All in advance,
ERAN

P.S: if there is away to do so, how can i get the data back to html input boxes from the text file.

prasanth

9:09 am on Jun 8, 2005 (gmt 0)

10+ Year Member



It is possible to store the information in the form of cookies. cookies are associated with variable names. you can set and get them in the client machine, try more on cookies.

eranfox

9:24 am on Jun 8, 2005 (gmt 0)

10+ Year Member



Hello prasanth
Thank you for your reply!

can you show me a small example of using cookies?

Thank you again,
ERAN

prasanth

9:39 am on Jun 8, 2005 (gmt 0)

10+ Year Member



see the below link to study more about cookies.
[netspade.com...]

eranfox

10:31 am on Jun 8, 2005 (gmt 0)

10+ Year Member



Thank you prasanth!
I think i'll use this to set and get values without using asp and etc...

Thank you very much!

ERAN

eranfox

12:28 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



prasanth,
a small question if i may,
i copied the code and opened the html file.
i clicked on the "Set Cookie!" link and after that i clicked on the "Get Cookie!" link.
i got the messege but can't find the cookie.
is it virtual? where can i find the physical txt file?

I searched the cookies folder but found nothing.

what's wrong?

Sanenet

12:42 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you set the cookie as a session (ie, vanishes when the browser is closed) or as long term? If it's session, it won't be saved in the cookies folder.

prasanth

9:29 am on Jun 10, 2005 (gmt 0)

10+ Year Member



There is a time limit for cookie to be stored. The time will be in seconds. give 86400 for one day, like that....

eranfox

6:52 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Reply to Sanenet and prasanth,
Hello and thank you for your replies!
I forgot to send the expire date as a parameter to the set cookie function
so now it is working just great.

Thank YOU BOTH,
Best Regards,
ERAN

eranfox

10:02 am on Jun 14, 2005 (gmt 0)

10+ Year Member



Hello All,
Now That i know how to create a cookie,
I want to add values to the cookie but i just don't know how.

Can you please HELP me?

Thank you ALL in advance,
ERAN

JAB Creations

11:21 pm on Jun 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.cookie='theme=Matrix Theme;path=/;time()+2592000;'

You can (thankfully) simply override a cookie.

Reading cookies via Javascript is NOT easy and by all means retarded. I suggest using a serverside script to read cookies however I find that there is a two page delay in retrieving new values in cookies. For example, if you set a new value on page16.php, visit page17.php, the server will not echo back the correct value until you visit page18.php. I think this just goes for echoing a value and I'm not sure but the serverside script MAY get the value after the second page loads, but I'm not sure really.

Here is how to echo a value in PHP...

<php echo $HTTP_COOKIE_VARS[mycookiename]);?>

eranfox

6:45 am on Jun 15, 2005 (gmt 0)

10+ Year Member



Reply to JAB Creations,
Hello and thank you for your reply!
i dont want to override all the information on the cookie, i want to change some of the values.

let me explain:
I need to build a simple form (well it is not that simple but just for the example...)
it will have 3 text boxes :
1)for the first number
2)for the second number
3)for the result
after the user will enter the numbers the result will be in the 3rd textbox (input box)

Now,i need to save this 3 values in the cookie.
also if the user will change the values ,the new values will have to override the old values from the cookie.
the html document and the cookie will be send to another user and he will be able to see the values entered by the first user.

i know this is stupid by my boss think its a good idea.
i almost got fired because i told him he was wrong.
i dont want to leave this place because it is 9:00-17:00 job and the salary is good.

please Help me on this.

BEST REGARDS,
ERAN

P.s. i can use only javascript - without PHP

JAB Creations

1:42 am on Jun 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Some good advice, you don't want to say your boss is wrong. You want to convince him you have found a more "effecient" method that you could "implement". This is essencially saying "I'm improving what we already have" without saying, "your system sucks". :-D

I'm no Javascript Guru so I wish you the best of luck...

I would (if I knew how to do this) try to take the value I want to keep from the cookie after reading the cookie, and pass them along and just rewrite the cookie. Thats just the way my brain works though, I'm not as dynamic as some of the other people here are. Best of luck!

eranfox

4:49 am on Jun 16, 2005 (gmt 0)

10+ Year Member



Reply to JAB Creations,
Again thank you for your reply,
And thank you for the advice.

I'll try to find a solution for this...
(Or maybe just give up)

Best Regards,
ERAN

sottwell

5:29 am on Jun 19, 2005 (gmt 0)

10+ Year Member



How will the document (with or without the cookie data) be sent to another user?

For security purposes, javascript was never permitted to write directly to the user's hard disk.

What web server are you using? Are the pages coming from a local web server, or from a remotely hosted site?

I need more information on your system. I've done this before (taught somebody how to do a HR database in QBasic of all things, but his boss was too cheap to buy anything decent, and QBasic came with DOS so that's what they had!

eranfox

11:49 am on Jun 19, 2005 (gmt 0)

10+ Year Member



Reply to sottwell,
Hello and thank you for your reply!
The idea was to send the coockie as a text file.
But,Finally my Boss got the picture and now i'm working on something else.
Sorry...

Best Regards,
ERAN

sottwell

11:31 am on Jun 20, 2005 (gmt 0)

10+ Year Member



I was going to recommend BadBlue, if you're using Windows in the office. Fantastic little web server/file sharing tool, not expensive at $60 for the full version, collaboration with Excel and Word, all sorts of things. I always use it as my local web server when I'm stuck developing on a Windows box. Excellent documentation for setting up back-end scripting (I use PHP).

[badblue.com ]