Use XMLHTTP Ajax to automatically save information complete JS code
Function Createhttphandler () {
var HttpHandler = false;
@if (@_jscript_version >= 5)
//JScript gives us conditional compilation, we can cope with old IE Versions. The
//and security blocked creation of the objects.
try {
httphandler = new ActiveXObject ("Msxml2.xmlhttp");
catch (e) {
try {
httphandler = new ActiveXObject (" Microsoft.XMLHTTP ");
}
catch (e) {
httphandler = false;
&NBSP}
if (!httphandler && typeof xmlhttprequest!= ' undefined ') {
HttpHandler = new XMLHttpRequest ();
}
return HttpHandler;
}
/**
* Auto saves as draft
*/
function Autosavedraft () {
Checks = 0;
seconds = Now ();
var title = encodeURI (Addform.title.value);
var BODY = encodeURI (addform.body.value);
var catid = Addform.catid.options[addform.catid.selectedindex].value;
var more = encodeURI (Addform.more.value);
var closed = 0;
if (addform.closed[0].checked) {
closed = Addform.closed[0].value;
}
else if (addform.closed[1].checked) {
closed = Addform.closed[1].value;
}
var ticket = Addform.ticket.value;
var querystring = ' Action=autodraft ';
querystring + = ' &title= ' + title;
querystring + = ' &body= ' + body;
querystring + = ' &catid= ' + catid;
querystring + = ' &more= ' + more;
querystring + = ' &closed= ' + closed;
querystring + = ' &ticket= ' + ticket;
if (FormType = = ' edit ') {
querystring + = ' &itemid= ' + addform.itemid.value;
&nbs P;querystring + = ' &type=edit ';
}
else {
querystring + = ' &blogid= ' + addform.blogid.value;
querystring = ' &type=add ';
}
if (Addform.draftid.value > 0) {
querystring + = ' &draftid= ' + addform.draftid.value;< br> }
Xmlhttprequest[0].open (' Post ', Goalurl, true);
Xmlhttprequest[0].onreadystatechange = Checkmonitor;
Xmlhttprequest[0].setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
Xmlhttprequest[0].send (querystring);
var querystring = ' action=updateticket&ticket= ' + ticket;
Xmlhttprequest[1].open (' Post ', Goalurl, true);
Xmlhttprequest[1].onreadystatechange = Updateticket;
Xmlhttprequest[1].setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
Xmlhttprequest[1].send (querystring);
}
/**
* Monitors the edits
*/
function Domonitor () {
if (Checks * (now ()-seconds) > 120 * 1000 * 50) {
Autosavedraft ();
}
else {
checks++;
}
}
/**
* checks the process of the saving
*/
Function Checkmonitor () {
if (xmlhttpreques T[0].readystate = = 4) {
if (xmlhttprequest[0].responsetext) {
if (XMLHttpRequest [0].responsetext.substr (0, 4) = = ' err: ') {
goal.innerhtml = xmlhttprequest[0]. RESPONSETEXT.SUBSTR (4) + ' (' + formatteddate () + ') ';
}
else {
addform.draftid.value = Xmlhttprequest[0].responsetext;
goal.innerhtml = lastsavedtext + ' + formatteddate ();
}
}
}
}
/**
* Checks the process of the ticket updating
*/
function Updateticket () {
if (xmlhttprequest[1].readystate = = 4) {
if (Xmlhttprequest[1].responsetext) {
if (xmlhttprequest[1].responsetext.substr (0, 4) = = ' err: ') {
goal.innerhtml = Xmlhttprequest[1].responsetext.substr (4) + ' (' + formatteddate () + ') ';
}
else {
Addform.ticket.value = Xmlhttprequest[1].responsetext;
}
}
}
}
/**
* Gets now in milliseconds
*/
function Now () {
var now = new Date ();
return Now.gettime ();
}
/**
* gets now on the local dateformat
*/
Function formatteddate () {
var now = new Da Te ();
return now.tolocaledatestring () + ' + now.tolocaletimestring ();
}