Results 1 to 7 of 7

Thread: [RESOLVED]How to save data from html to text file?

  1. #1

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    [RESOLVED]How to save data from html to text file?

    Hello Everybody,
    Is there a way to save data from HTML file to a text file on the client side only without using ASP,CGI,ETC...
    I think cookie is the solution ,but i tried to save a cookie and failed.
    i dont know why i will send the code tommorow morning.

    Thank you all in advance,
    ERAN
    Last edited by eranfox; Jun 9th, 2005 at 09:43 AM. Reason: [RESOLVED]
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: How to save data from html to text file?

    Quote Originally Posted by eranfox
    Hello Everybody,
    Is there a way to save data from HTML file to a text file on the client side only without using ASP,CGI,ETC...
    I think cookie is the solution ,but i tried to save a cookie and failed.
    i dont know why i will send the code tommorow morning.

    Thank you all in advance,
    ERAN
    No, you cannot use a cookie.
    A cookie has a character (Or is it a size) limit... either way a HTML file would be too big to save.

    Why would you need to do this anyway?

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  3. #3
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: How to save data from html to text file?

    to do this, you would need to make a simple script (ASP, CGI/PERL, PHP, JSP, CFM, exc...)

    and like sciguyryan said... you are limited on how many caracters a cookie can handle, and the cookie would be saved on the client side of the transaction. also, the cookie would have wierd caracters in it anyway, depending on the browser.

    -ALL

    PS: i am not 100% sure but... saving a cookie would require a scripting language aswell, unless Javascript could do it (but i dont think it can [but not sure])
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  4. #4

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: How to save data from html to text file?

    Thank you for your replies sciguyryan and ALL,
    a few details and facts:
    1)a cookie can contain up to 4000 characters.
    2)i got this assignment from my boss.
    3)i need to build a HTML form that will work on a "psion-netbookpro" - you can read about it in www.psionteklogix.com/public.aspx?s=com&p=Products&pCat=128&pID=1699
    if you think this is a commercial add please let me know and i'll delete it!!!
    4)this computer is working with windows CE
    5)when i used EXCEL with VBA it ignored the VBA Code.
    6)that is why i need to use HTML.
    7)I can use javascript but not vbscript.
    8)i dont need to save all the HTML Document
    9)i need to save only the values entered by the user.
    10)after the user finish his work on the form he will send it by e-mail to his boss.
    11)the cookie that stores the data entered will be send as well.
    12)the code i'm using was taken from this site:
    www.netspade.com/articles/javascript/cookies.xml
    13)its working but somehow i cant find the cookie
    14)my code is just for the test:
    Code:
    <HTML>
    <HEAD>
    <SCRIPT type="text/javascript" language="javascript">
    /**
     * Sets a Cookie with the given name and value.
     *
     * name       Name of the cookie
     * value      Value of the cookie
     * [expires]  Expiration date of the cookie (default: end of current session)
     * [path]     Path where the cookie is valid (default: path of calling document)
     * [domain]   Domain where the cookie is valid
     *              (default: domain of calling document)
     * [secure]   Boolean value indicating if the cookie transmission requires a
     *              secure transmission
     */
    function setCookie(name, value, expires, path, domain, secure)
    {
        document.cookie= name + "=" + escape(value) +
            ((expires) ? "; expires=" + expires.toGMTString() : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
    }
    
    /**
     * Gets the value of the specified cookie.
     *
     * name  Name of the desired cookie.
     *
     * Returns a string containing value of specified cookie,
     *   or null if cookie does not exist.
     */
    function getCookie(name)
    {
        var dc = document.cookie;
        var prefix = name + "=";
        var begin = dc.indexOf("; " + prefix);
        if (begin == -1)
        {
            begin = dc.indexOf(prefix);
            if (begin != 0) return null;
        }
        else
        {
            begin += 2;
        }
        var end = document.cookie.indexOf(";", begin);
        if (end == -1)
        {
            end = dc.length;
        }
        return unescape(dc.substring(begin + prefix.length, end));
    }
    
    /**
     * Deletes the specified cookie.
     *
     * name      name of the cookie
     * [path]    path of the cookie (must be same as path used to create cookie)
     * [domain]  domain of the cookie (must be same as domain used to create cookie)
     */
    function deleteCookie(name, path, domain)
    {
        if (getCookie(name))
        {
            document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <A href="#" onclick='setCookie("name", "eran fox")'>Set Cookie!</A>
    <A href="#" onclick='alert(getCookie("name"))'>Get Cookie!</A>
    </BODY>
    </HTML>
    15)when i click on Get Cookie! after i clicked on Set Cookie! i see the alert message but cant find any cookie

    16)I need your H E L P ! ! !

    Thank you all in advance,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  5. #5
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: How to save data from html to text file?

    Quote Originally Posted by ALL
    PS: i am not 100% sure but... saving a cookie would require a scripting language aswell, unless Javascript could do it (but i dont think it can [but not sure])

    Yes you can save cookies using Javascript

    The document.cookie property is used to access and modify then

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  6. #6

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: How to save data from html to text file?

    Reply to sciguyryan,

    Originally Posted by sciguyryan:
    Yes you can save cookies using Javascript
    The document.cookie property is used to access and modify then
    Hello sciguyryan,
    can you tell me please, why i can't see the cookie?

    Thank you in advance,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  7. #7

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Smile Re: How to save data from html to text file?

    [RESOLVED]
    Hello Everybody,
    i found the problem in my javascript function.
    i thougth that if i wont pass the expire date the cookie will be save on the local computer.
    I WAS WRONG!!!

    HERE IS THE WORKING CODE:
    Code:
    </HEAD>
    <BODY>
    <A href="#" onclick='setCookie("name", "eran fox","December 31, 2999")'>Set Cookie!</A>
    <A href="#" onclick='alert(getCookie("name"))'>Get Cookie!</A>
    </BODY>
    </HTML>
    I JUST SET THE EXPIRE DATE TO 31/12/2999 AND IT WORKS JUST FINE.

    HAVE A NICE WEEKEND YOU ALL,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width