SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    Don't get too close, I bite! Nicky's Avatar
    Join Date
    Jul 1999
    Location
    Lancashire, UK
    Posts
    8,277
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Saving as a Text File

    Hello

    Does anyone know of any way that exsists where i can save a text file from the contents of a form. There is a blog with a database but it would be far superior if i saved the text as an .inc file wich did something like

    onSubmit="saveFile()"
    function saveFile()
    {
    txt = txt + a + b + c
    save txt
    }

    Thanks

  2. #2
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The FileSystemObject allows the saving and loading of text-files, but unfortunately it will not work client-side due to security restrictions.

    However, what you can do is have the form open a new window and write the contents of the form into it, so that you can use the browser File > Save command. But I am a little confused by your question; are you trying to save the contents of a form in one of your own pages, or those of another site?
    Of course, that's just my opinion. I could be wrong.

  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You might also try the saveAs dialog box and an iframe:

    Code:
    <script type="text/javascript">
    <!--
    function saveIt(formObj)
    { 
       var txt = '';
       for (i = 0; i < formObj.length; i++)
       {
    	 txt += formObj.elements[i].name + ' = ' + formObj.elements[i].value + "<br>";
       }
       theFrame.document.open("text/html","replace") 
       theFrame.document.write(txt) 
       theFrame.document.close() 
       theFrame.focus() 
       theFrame.document.execCommand('SaveAs',true,'myfile.txt') 
    } 
    //-->
    </script>
    </head>
    <body>
     <iframe id="theFrame" style="display:none"></iframe> 
    <form>
    <input type='text' name="a">
    <textarea name="b"></textarea>
    <input type='button' value='save it' onclick='saveIt(this.form)'>
    </form>
    You do realize, though, this only works with windows/ie?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  4. #4
    Don't get too close, I bite! Nicky's Avatar
    Join Date
    Jul 1999
    Location
    Lancashire, UK
    Posts
    8,277
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I want to save it on a page on my own site. It might be OK to do IE only as for the time being it is Intranet only.

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    save it on a page on my own site
    Why can't you use php/asp/etc?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  6. #6
    SitePoint Guru siphilp's Avatar
    Join Date
    Nov 2001
    Location
    Fife, Scotland
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why not use inline editing function for IE? So once you have done all your changes you can submit it back to the database, well that's if you use one? Obvioulsy if you wanted it to save as an inc file then your using some sort of scripting language


Bookmarks

Posting Permissions

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