...

View Full Version : Write a textarea to a file



cc.shine
06-23-2003, 08:39 PM
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>

raf
06-23-2003, 08:51 PM
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


<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


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

cc.shine
06-23-2003, 09:08 PM
:DThank you!!!:D

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

raf
06-23-2003, 09:42 PM
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)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum