-1

I know it were talked lots about that, but I have tried lot of these options and with no success, please let me know what I have done wrong here:

   <html>
   <head>
   <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
   <title>IP</title>
   <%
   function su192168165()
       Dim fso192168165, f, filespec, wrln
       set wrln = Document.getElementById(192168165).Value
       Set fso192168165 = CreateObject("Scripting.FileSystemObject")
       filespec = Server.Mappath("/comment/192168165Comments.txt")
       Set f = fso192168165.OpenTextFile(filespec,2)
       f.WriteLine wrln
       f.Close
   End function
   %>
   </head>
   <body>
   <input type="text" id="192168165" name="Comment" value=""/><input type="button" value="Comment" onclick="su192168165()"/>
   </body>
   </html>

This is my HTML code that contain place to write comment and after clicking on button it is need to write the comment to file, but it is not functioning.

I have also tried to replace the functions with sub, same problem. Code 0 on line 8. "set wrln = Document.getElementById(192168165).Value"

Please help and let me know what I have wrote here wrong. Thanks Tal

Tal Shl
  • 1
  • 1
  • 1

1 Answers1

2

What you are doing is impossible on multiple levels. To give you a quick overview of the problem That you have here:

You cannot do this kind of writing to server files from a simple onClick method.

That is not saying that this is impossible just that you cannot do it in the way you seem to think you can at all.

Just to start, I want to highlight what is wrong with the code from a basic perspective. Your onClick method is trying to call a VBScript function. This is impossible. What you have to understand is that VBScript is a server scripting language while onClick an event handler that normally triggers javascript which runs on the client. Once the client downloads this page the server has run this code and effectively no longer exists. The server does not pass the VBScript function to the client.

Hopefully that makes sense and should only leave the question of how can you accomplish the task you want to perform. The simple way which I would recommend would be to add a form for that field and have the button post the form back to the same page. You can then use the Request.Form method to call the field in your function. You would also want to change the function to a simple if condition which would check if you posted back from the button. How you chose to do that is up to you.

Let's say that the above method does not work for you. For some reason you cannot do a postback. You absolutely need to do this asynchronously for some reason. In this case you are going to need to develop an Ajax call. You can look at this SO link on doing the same thing in PHP to help you understand what you will need to know to start out with this method: Saving a text file on server using JavaScript.

Otherwise you are going to have to look around yourself for tutorials on how to do asynchronous postbacks in classic asp. Good luck.

Community
  • 1
  • 1
KHeaney
  • 785
  • 8
  • 18
  • 1
    Just to confuse things VBScript is a "scripting language" and can be both client-side and server-side, in terms of working with Classic ASP it is the default scripting language used "server-side". Also if you do use VBScript client-side you will find it is unsupported by most browsers with the exception of Internet Explorer. – user692942 Nov 24 '14 at 14:59
  • 1
    Please do confuse **VB** with VBScript they are different. VB is a fully fledged programming language while VBScript is a scripting language equivalent. – user692942 Nov 24 '14 at 15:00
  • 1
    How does introducing another technology (PHP in this case) help the OP? – user692942 Nov 24 '14 at 15:01
  • 1
    @Lankymart on the link: I can see why it does not seem as relevant as it is a different language but honesly when I have searched for classic asp examples for asynch postback I felt that they were more difficult to understand than this one which is much more lean and simple to understand what is going on in general which is all I wanted to convey. On using just VB: yeah that is a bad habit just use to talking to people using only VB instead of the full VBScript. – KHeaney Nov 24 '14 at 15:16
  • 2
    What is there to understand all your AJAX logic is client-side *(most likely JavaScript)* and the ASP code can be as simple as `Response.Write "hello"` it's entirely how you decide to send the data to Classic ASP and how you expect it back that determines what code is needed. All interactions in Classic ASP are `Request` -> `Response` whether it's GET, POST or Asynchronous JavaScript. – user692942 Nov 24 '14 at 15:22