consultancy chorley ASP.NET Server Side Scripting Wigan
Website Development Radcliffe

A Coder's Notes

Email :
bespoke invoice systems Standish Information Technology Advice Worsley
    development systems Ramsbottom
data manipulation Farnworth access databases Whitefield SQL connections Atherton
online accessible software Leyland software compatible Coppull

Get connected and Online Tottington
remote management Makerfield code and design Aspull

Auto Save A Textarea - Javascript (And Ajax) - 21/05/2014

This is another one of those things that is made VERY complex on the internet. Here's my simple version.

*The page containing the text area you wish to auto save*
<!DOCTYPE html>
function mysave()
var xmlhttp;
xmlhttp=new XMLHttpRequest();"POST","savepage.aspx", true);
xmlhttp.send("text=" + document.getElementById("mybox").value);
<body onload = "setInterval(function(){mysave()},5000);" >
<form runat="server">
<asp:textbox id = "mybox" textmode = "multiline" width = "400px" height = "400px" runat = "server" />
Now, note the javascript in bold.
 1. We create the variabe "var".
 2. We make var a new XMLHttpRequest() 
 3. We open for "POST", use post rather than "GET" because you might have a very large amount of data in your text area.
 4. We add the header. I don't know why, if you want to know look elsewhere!
 5. We send the request. Basically the javascript in your browser asks for the webpage stated in the When it asks for it it also sends the POST data found in "mybox", which will be the name and id of your text area. 
Unlike many Ajax calls we are NOT expecting a response. We just request the page with the contents of the text area. 
In the instance above we request the page "savepage.aspx". If like my you're an ASP.Net programmer the page can collect the text area details thusly
dim textareatosave as string
textareadatatosave = request("text")
Then save it. Save it to a file or database, that's up to you. 

Post A Comment

Name Comment
programming services specialist
Valid XHTML 1.0 Transitional