f



AJAX forms

If I have a form where people write stuff and post it (a forum, say) - when=
 they click "Post", I want the form to disappear, and a "Message posted" or=
 whatever text to appear, via AJAX.... - my question is, after the message =
has been posted, ie. the server side replies with an "OK" or whatever, how =
do I get rid of the form on the page and replace it with the "Message poste=
d" text? Is it removeChild? I assume this would work....?: x.parentNode.rep=
laceChild(document.createTextNode("Message Posted"), n) ; =20


But I also saw this sample code in my book (for showing how this sort of st=
uff is done, not specifically for MY case):

var b =3D document.createElement("b");
parent.replaceChild(b, n);   // Replace node n with the <b> element
b.appendChild(n); // Make n a child of the <b> element

I'm not understanding what the "appendChild" is for - surely replaceChild b=
y itself will put in the Bold element? Why is the appendChild needed after =
that?

Thanks.


0
bit
10/14/2016 8:15:27 PM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

5 Replies
400 Views

Similar Articles

[PageSpeed] 1

In article <853ac26d-01db-49dd-9d77-62f49b7fcaae@googlegroups.com>,
<bit-naughty@hotmail.com> wrote:

>If I have a form where people write stuff and post it (a forum, say) - when
>they click "Post", I want the form to disappear, and a "Message posted" or
>whatever text to appear, via AJAX.... - my question is, after the message has
>been posted, ie. the server side replies with an "OK" or whatever, how do I
>get rid of the form on the page and replace it with the "Message posted" text?

If you have a proper form, as in the <form> element, simply submitting
it (no AJAX needed) will send the form information to the server. It's
up to you to write the script on the server to process that and return
a new HTML page to be displayed which will replace the form page.
Shouldn't need any javascript for that.

-- 
New Socialism consists essentially in being seen to have your heart in 
the right place whilst your head is in the clouds and your hand is in 
someone else's pocket.
0
Tim
10/14/2016 8:42:02 PM
Umm... hello? Does anyone know??
0
bit
10/19/2016 1:43:07 PM
In article <92579258-7c30-4af0-83b7-01932e9a6a0e@googlegroups.com>,
<bit-naughty@hotmail.com> wrote:

>Umm... hello? Does anyone know??

Does anyone know what?

-- 
"Please stop telling us what you feel. Please stop telling us what your 
intuition is. Your intuitive feelings are of no interest whatsoever, 
and nor are mine. I don't give a bugger what you feel, or what I feel. 
I want to know what the evidence shows."             -- Richard Dawkins
0
Tim
10/19/2016 2:07:50 PM
>var b = document.createElement("b"); 
parent.replaceChild(b, n);   // Replace node n with the <b> element 
b.appendChild(n); // Make n a child of the <b> element

The idea here may be to remove node n, and then to re-insert it under the new <b> node. It is one way to make an existing text (in n) bold.
0
Ram
10/20/2016 5:20:14 PM
On Thu, 20 Oct 2016 10:20:14 -0700 (PDT), Ram Tobolski wrote:
>>var b = document.createElement("b"); 
> parent.replaceChild(b, n);   // Replace node n with the <b> element 
> b.appendChild(n); // Make n a child of the <b> element
> 
> The idea here may be to remove node n, and then to re-insert it under the new <b> node. It is one way to make an existing text (in n) bold.

You can do the same without removing node `n` from the document.

  var b = document.createElement("b"); 
  parent.insertBefore(b, n); //put element `b` before node `n`
  b.appendChild(n);          //move node `n` into element `b`
0
JJ
10/21/2016 1:37:57 PM
Reply: