The examples in this article describe the way JavaScript edits information based on Ajax. Share to everyone for your reference. as follows:
Requires prototype.js function edit (action, obj) {element.hide (obj); var textarea = ' <div id= ' + obj.id + ' _editor ' ><input type= ' text ' id= ' + obj.id + ' _edit ' name= ' + obj.id + ' '
Value= "' + obj.innerhtml + '" "size=" > "; var button = ' <input id= ' + obj.id + ' _save ' type= ' button ' value= ' save '/> <input ' id= ' + obj.id + ' _cancel ' Typ
E= "button" value= "Cancel"/></div> ";
New Insertion.after (obj, Textarea+button);
Event.observe (obj.id+ ' _save ', ' click ', Function () {saveChanges (action, obj)}, False);
Event.observe (obj.id+ ' _cancel ', ' click ', Function () {cleanUp (obj)}, False);
$ (obj.id+ "_edit"). focus ();
$ (obj.id+ "_edit"). Select ();
function cleanUp (obj, keepeditable) {element.remove (obj.id+ ' _editor ');
Element.show (obj);
if (!keepeditable) showaseditable (obj, true);
function saveChanges (action, obj) {var new_content = Escape ($F (obj.id+ ' _edit '));
obj.innerhtml = "Saving ...";
CleanUp (obj, true); var success = function (t) {EDITCOmplete (t, obj);}
var failure = function (t) {editfailed (t, obj);}
var url = ' poll-ajax.php?a= ' +action;
var pars = ' id= ' + obj.id + ' &content= ' + new_content;
var myajax = new Ajax.request (URL, {method: ' Post ', Postbody:pars, Onsuccess:success, onfailure:failure});
function Editcomplete (t, obj) {obj.innerhtml = T.responsetext;
Showaseditable (obj, true);
function editfailed (t, obj) {obj.innerhtml = ' Sorry, the update failed. '
CleanUp (obj);
}
The
wants this article to help you with your JavaScript programming.