Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31573 > unrolled thread

AJAX forms

Started bybit-naughty@hotmail.com
First post2016-10-14 13:15 -0700
Last post2016-10-21 20:37 +0700
Articles 6 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  AJAX forms bit-naughty@hotmail.com - 2016-10-14 13:15 -0700
    Re: AJAX forms Tim Streater <timstreater@greenbee.net> - 2016-10-14 21:42 +0100
    Re: AJAX forms bit-naughty@hotmail.com - 2016-10-19 06:43 -0700
      Re: AJAX forms Tim Streater <timstreater@greenbee.net> - 2016-10-19 15:07 +0100
    AJAX forms Ram Tobolski <ramtob@gmail.com> - 2016-10-20 10:20 -0700
      Re: AJAX forms JJ <jj4public@vfemail.net> - 2016-10-21 20:37 +0700

#31573 — AJAX forms

Frombit-naughty@hotmail.com
Date2016-10-14 13:15 -0700
SubjectAJAX forms
Message-ID<853ac26d-01db-49dd-9d77-62f49b7fcaae@googlegroups.com>
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? Is it removeChild? I assume this would work....?: x.parentNode.replaceChild(document.createTextNode("Message Posted"), n) ;  


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

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

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

Thanks.

[toc] | [next] | [standalone]


#31574

FromTim Streater <timstreater@greenbee.net>
Date2016-10-14 21:42 +0100
Message-ID<141020162142022847%timstreater@greenbee.net>
In reply to#31573
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.

[toc] | [prev] | [next] | [standalone]


#31586

Frombit-naughty@hotmail.com
Date2016-10-19 06:43 -0700
Message-ID<92579258-7c30-4af0-83b7-01932e9a6a0e@googlegroups.com>
In reply to#31573
Umm... hello? Does anyone know??

[toc] | [prev] | [next] | [standalone]


#31587

FromTim Streater <timstreater@greenbee.net>
Date2016-10-19 15:07 +0100
Message-ID<191020161507504405%timstreater@greenbee.net>
In reply to#31586
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

[toc] | [prev] | [next] | [standalone]


#31591

FromRam Tobolski <ramtob@gmail.com>
Date2016-10-20 10:20 -0700
Message-ID<1201e9f8-ba42-4f29-b999-989ac5d28f7a@googlegroups.com>
In reply to#31573
>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.

[toc] | [prev] | [next] | [standalone]


#31593

FromJJ <jj4public@vfemail.net>
Date2016-10-21 20:37 +0700
Message-ID<1cre59bjnmw8w$.9ryhfgtdeumv$.dlg@40tude.net>
In reply to#31591
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`

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web