Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Write a textarea to a file

    Ok, this should be a simple question for anyone other than a beginner like me...

    I'm trying to write the contents of a textarea to a file. I have the code to write to the file, I just can't figure out how to pass the content/value of the text area to a variable, then to the file on a button click. My knowledge of forms is extremely limited, so I'm not sure what method and/or action to use in conjunction with this.

    TIA.

    <form action="" method="post" name="UpdateACOE">

    <textarea name="txtUpdateACOE" cols="60" rows="20"></textarea>

    <input name="save" type="button" id ="save" value="Save">

    sub save_onclick
    dim Str
    Str = request("txtUpdateACOE")

    dim objFSO
    set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    if objFSO.FileExists ("acoe.txt") then
    dim objTextStream
    set objTextStream = objFSO.OpenTextFile ("acoe.txt", 2)
    objTextStream.write str
    objTextStream.Close
    set objTextStream = Nothing
    Set objFSO = Nothing
    end if
    end sub
    </script>
    </form>

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think youu're kinda confused. Normally, you have
    - an HTML (or ASP) page with the form in
    - a page where the form is posted to (can be the same or another page) that does the server sided action --> in your case, write to the txt.

    So in the html file, you'd have something like
    Code:
    <form action="page2.asp" method="post" name="UpdateACOE">
      <textarea name="txtUpdateACOE" cols="60" rows="20"></textarea>
      <input type="submit" value="Save" name="save">
    </form>
    When they hit the submit button, the form is posted to the page in the 'action' --> page2.asp
    Then, in page2.asp, you'll have something like
    Code:
    dim Str
    Str = request.form("txtUpdateACOE")
    
    dim objFSO
    set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    if objFSO.FileExists ("acoe.txt") and Len(Str)>0 then 
      dim objTextStream
      set objTextStream = objFSO.OpenTextFile ("acoe.txt", 2)
      objTextStream.write Str
      objTextStream.Close
      set objTextStream = Nothing
      Set objFSO = Nothing
    else
      response.write("Problem")
    end if

  • #3
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you!!!

    Actually I was very confused. My head aches from trying to figure everything out on my own, so I greatly appreciate the help. I knew it would be simple for someone else, but I've never actually done anything with info from a form where there wasn't sample code already available, including the cgi script.


    Thanks again!!
    Cathleen

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No problem.

    We all had to learn it sometime. Maybe run a search on this forum for some good tutorials, or take a look around here
    http://www.w3schools.com/
    (might save you some headaches)


  •  

    Posting Permissions

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