473,320 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using Ajax to create a button to save a text???

I am very newbie in ajax, so please forgive me if my question are so dump.
I want to create a box where user can type a message and when they click "Save" button. That text will be save. I got the function writefile to work. I named it writefile.asp. But my problem is creating ajax to implement the writefile.asp when user click on "Save" button. Here is what I got so far. Please help
Here is my form.asp
<%@Language=JavaScript%>
Expand|Select|Wrap|Line Numbers
  1. <%@Language=JavaScript%>
  2. <html>
  3. <body>
  4. <%
  5. function Save(){
  6.       var xmlhttp;
  7.       try{
  8.           xmlhttp = new XMLHttpRequest();
  9.       }catch(e){
  10.           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
  11.       }
  12.     xmlhttp.open("GET", "writefile.asp", true);
  13.       xmlhttp.onreadystatechange = function(){
  14.           if(xmlhttp.readyState == 4){
  15.               Response.Write("Message's Detail Has Been Successfully Saved");
  16.           }
  17.  
  18.       }
  19.       xmlhttp.send(null);
  20.   }
  21. %>
  22. <textarea rows="20" name="message" cols="20"></textarea>
  23. <p>
  24. <input type="button" value="Save Detail" name="saveDetail" onClick="Save();">
  25. </p>
  26. </body>
  27. </html>
  28.  
  29.  
  30.  
Jun 13 '07 #1
5 2198
epots9
1,351 Expert 1GB
what does your writefile.asp look like?
Jun 13 '07 #2
it may sound weird but, writefile.asp is written in VBscript not javascript, since javascript does not support write to file. Here is the code. Both writefile.asp and form.asp is in the same folder
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3.  
  4.     dim filesys, filetxt, messageDetail
  5.     Const ForReading = 1, ForWriting = 2, ForAppending = 8
  6.     Set filesys = CreateObject("Scripting.FileSystemObject")
  7.     Set filetxt = filesys.OpenTextFile("c:\CiscoIPServices\ASP\push2phone\alert.xml", ForWriting, True)
  8.  
  9.     messageDetail = Request.Form("detail").Item
  10.     message = Request.Form("message").Item
  11.     phoneDetail = Request.Form("phones").Item;
  12.  
  13.     filetxt.WriteLine("<CiscoIPPhoneText>")
  14.     filetxt.WriteLine("<Title>Alert</Title>")
  15.     filetxt.WriteLine("<Prompt>Select an option</Prompt>")
  16.     filetxt.Write("<Text>")
  17.     filetxt.Write(messageDetail)
  18.     filetxt.WriteLine("</Text>")
  19.     filetxt.WriteLine("</CiscoIPPhoneText>")
  20.     filetxt.Close
  21.  
  22. %>
  23.  
  24.  
  25.  
  26.  
  27.  
Jun 13 '07 #3
acoder
16,027 Expert Mod 8TB
You have two problems. On line 15 of your Ajax code, you have used ASP code. You need to convert that to Javascript, maybe an alert will do.

Secondly, you're just calling the file, but not passing it anything. You need to pass some info. when making a request.
Jun 14 '07 #4
You have two problems. On line 15 of your Ajax code, you have used ASP code. You need to convert that to Javascript, maybe an alert will do.

Secondly, you're just calling the file, but not passing it anything. You need to pass some info. when making a request.

will you explain it a bit more. What do I have to pass there? I call the function Save() when there is onClick. But I dont think it ever get inside the function. What is going on here?
Jun 14 '07 #5
acoder
16,027 Expert Mod 8TB
"writefile.asp" needs to have message passed to it, so that it can be saved, e.g. "writefile.asp?message=blahblah".

You may want to consider making a POST request instead where you would send message in the send method (instead of null).

Give the textarea message an id, e.g. "message" and access it using:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('message').value;
Jun 15 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: C Watson | last post by:
Hi, I'm wondering if anyone can help me with AJAX in ASP.NET 1.1. I have a very specific feature that I would like to use it for. I have a rather long form that the users use to enter data...
4
by: s.bussing | last post by:
Hi All, I'm new to Atlas and I did some programming using AJAX, but I'm wondering if it is possible to hava a javascript which can call a server-site function, in my case to write data to the...
0
by: =?Utf-8?B?TWljaGFlbCBkZSBWZXJh?= | last post by:
To all, I'm trying to use ajax in my web site project but everytime I hit the button on my webform the whole page posts back. The label control that I have in my update panel does what it is...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
1
by: mbruyns | last post by:
i have been trying (and sometimes succeeding) to use the modalpopupextender to show various panels of controls on my asp pages. the strange problem that i keep on running into is that sometimes it...
10
by: dkyadav80 | last post by:
<html> /// here what shoud be java script for: ->when script run then not display all input text field only display selection field. ->when user select other value for institute only this...
8
omerbutt
by: omerbutt | last post by:
hi there i have a form with multiple input (type/text ) fields and three inputs(type/file) fields i have to submit the form via ajax because i have multiple forms on this page ,you can say it is a...
5
by: temijojo | last post by:
Hello, Can someone help me in this problem. In my content page, I used 2 user controls inside an Ajax Toolkit TabControl. One of the user controls is a data entry with a dropdownlist. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.