Append AJAX Response Message

I use the following code to submit a form and get a response using AJAX.

When the form has been submitted, a response in placed in placeholder div: "Successfully Saved"

Now you only ever see on response: "Successfully Saved"

I want the response to be APPENDED to the contents of the placeholder div, not to replace the contents.

So if a user submits the form 10 times they should see 10 messages: "Successfully Saved" -- each one under the one before it.
LVL 16
Who is Participating?
David S.Commented:
"Successfully Saved" comes in the AJAX response. While you could modify SACK, I don't recommend it.

Try this:
var numContainers = 1;
function doit(){
  var box = document.getElementById('container');
  var box2 = document.createElement('div'); = 'container'+(++numContainers);
	var form = document.getElementById('form');
	ajax.setVar("myTextBox", form.mytext.value); // recomended method of setting data to be parsed.
	ajax.requestFile = "5process.html";
	ajax.method = form.method.value;
	ajax.element = 'container'+numContainers;
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;

Open in new window

In your line of code that sets the wording in the div - something like:

document.getElementById('divID').innerHTML = 'Successfully Saved';

change to:

document.getElementById('divID').innerHTML = document.getElementById('divID').innerHTML + '<br/>Successfully Saved';
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.