Append AJAX Response Message

Posted on 2009-02-10
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.
Question by:hankknight
    LVL 11

    Expert Comment

    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';
    LVL 42

    Accepted Solution

    "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


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now