We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Append AJAX Response Message

hankknight asked
Medium Priority
Last Modified: 2012-08-13
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.
Watch Question

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';
Consultant & Challenge Subduer
Top Expert 2009
"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');
  box2.id = '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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.