Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

If the facts don't fit the theory, change the facts. -- Albert Einstein


devel / comp.lang.javascript / AJAX scope problem

SubjectAuthor
* AJAX scope problembill
+* Re: AJAX scope problemJJ
|`* Re: AJAX scope problemJJ
| `* Re: AJAX scope problembill
|  `- Re: AJAX scope problemJJ
`- Re: AJAX scope problembill

1
AJAX scope problem

<si2ni7$1cge$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17269&group=comp.lang.javascript#17269

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!5rX/CuUHQjLlpkAtZPIqeA.user.46.165.242.75.POSTED!not-for-mail
From: william@TechServSys.com (bill)
Newsgroups: comp.lang.javascript
Subject: AJAX scope problem
Date: Fri, 17 Sep 2021 14:42:15 -0400
Organization: Aioe.org NNTP Server
Message-ID: <si2ni7$1cge$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="45582"; posting-host="5rX/CuUHQjLlpkAtZPIqeA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
X-Mozilla-News-Host: news://nntp.aioe.org:119
 by: bill - Fri, 17 Sep 2021 18:42 UTC

As part of a response I create a form. When the user clicks one
of two buttons I invoke a javascript function:
<input type="button" name="submit" value="Update"
onclick="javascript:saveItem()"/>
here is the top of that function----------------

function saveItem () { // save updated Item - from itemsToEdit
alert ("saveItem - entering 208")
alert ("saveItem - " + document.getElementById("EditItemsForm");

The problem is that returns null, as if the form did not exist,
but inspection of the source shows it present.

I presume the problem is that the form has not been created when
the .js is evaluated even though it is there by the time it is
executed.

I have many similar functions that work fine but this is the only
one that references a form created on the fly.

The apparent solution is to move the form definition to a static
part of the script but I don't know how to reference it so that
it appears when the onclick event happens.

--bill

Re: AJAX scope problem

<1k6gcpx667ja9.1szyt9uqb1722$.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17270&group=comp.lang.javascript#17270

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!MFL9HJkb5TxOiTbNd+TBqw.user.46.165.242.91.POSTED!not-for-mail
From: jj4public@gmail.com (JJ)
Newsgroups: comp.lang.javascript
Subject: Re: AJAX scope problem
Date: Sat, 18 Sep 2021 22:40:48 +0700
Organization: Aioe.org NNTP Server
Message-ID: <1k6gcpx667ja9.1szyt9uqb1722$.dlg@40tude.net>
References: <si2ni7$1cge$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="32618"; posting-host="MFL9HJkb5TxOiTbNd+TBqw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: 40tude_Dialog/2.0.15.84
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Notice: Filtered by postfilter v. 0.9.2
 by: JJ - Sat, 18 Sep 2021 15:40 UTC

On Fri, 17 Sep 2021 14:42:15 -0400, bill wrote:
> As part of a response I create a form. When the user clicks one
> of two buttons I invoke a javascript function:
> <input type="button" name="submit" value="Update"
> onclick="javascript:saveItem()"/>
> here is the top of that function----------------
>
> function saveItem () { // save updated Item - from itemsToEdit
> alert ("saveItem - entering 208")
> alert ("saveItem - " + document.getElementById("EditItemsForm");
>
> The problem is that returns null, as if the form did not exist,
> but inspection of the source shows it present.
>
> I presume the problem is that the form has not been created when
> the .js is evaluated even though it is there by the time it is
> executed.
>
> I have many similar functions that work fine but this is the only
> one that references a form created on the fly.
>
> The apparent solution is to move the form definition to a static
> part of the script but I don't know how to reference it so that
> it appears when the onclick event happens.
>
> --bill

Either the needed element has the wrong ID, or is served within an IFRAME.

Re: AJAX scope problem

<1v6fu43pso1x7$.1puo9tieoc9l3$.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17271&group=comp.lang.javascript#17271

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!MFL9HJkb5TxOiTbNd+TBqw.user.46.165.242.91.POSTED!not-for-mail
From: jj4public@gmail.com (JJ)
Newsgroups: comp.lang.javascript
Subject: Re: AJAX scope problem
Date: Sat, 18 Sep 2021 22:41:16 +0700
Organization: Aioe.org NNTP Server
Message-ID: <1v6fu43pso1x7$.1puo9tieoc9l3$.dlg@40tude.net>
References: <si2ni7$1cge$1@gioia.aioe.org> <1k6gcpx667ja9.1szyt9uqb1722$.dlg@40tude.net>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="32623"; posting-host="MFL9HJkb5TxOiTbNd+TBqw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: 40tude_Dialog/2.0.15.84
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Notice: Filtered by postfilter v. 0.9.2
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
 by: JJ - Sat, 18 Sep 2021 15:41 UTC

On Sat, 18 Sep 2021 22:40:48 +0700, JJ wrote:
>
> Either the needed element has the wrong ID, or is served within an IFRAME.

Or is within a Shadow DOM.

Re: AJAX scope problem

<si5apb$163a$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17272&group=comp.lang.javascript#17272

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!5rX/CuUHQjLlpkAtZPIqeA.user.46.165.242.75.POSTED!not-for-mail
From: william@TechServSys.com (bill)
Newsgroups: comp.lang.javascript
Subject: Re: AJAX scope problem
Date: Sat, 18 Sep 2021 14:22:35 -0400
Organization: Aioe.org NNTP Server
Message-ID: <si5apb$163a$1@gioia.aioe.org>
References: <si2ni7$1cge$1@gioia.aioe.org>
<1k6gcpx667ja9.1szyt9uqb1722$.dlg@40tude.net>
<1v6fu43pso1x7$.1puo9tieoc9l3$.dlg@40tude.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="39018"; posting-host="5rX/CuUHQjLlpkAtZPIqeA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: bill - Sat, 18 Sep 2021 18:22 UTC

On 9/18/2021 11:41 AM, JJ wrote:
> On Sat, 18 Sep 2021 22:40:48 +0700, JJ wrote:
>>
>> Either the needed element has the wrong ID, or is served within an IFRAME.
>
> Or is within a Shadow DOM.
>

On 9/18/2021 11:41 AM, JJ wrote:
> On Sat, 18 Sep 2021 22:40:48 +0700, JJ wrote:
>>
>> Either the needed element has the wrong ID, or is served
within an IFRAME.
>
> Or is within a Shadow DOM.
>
to explain in somewhat more detail:
I have 2 nested divs
The user enters data into a text box in the outer div. This
triggers a NEW XMLHtttpRequest which invokes a .php script.
The output of the script lists the search data in the 2nd div
with a button to edit the selected data item.

The button click calls a js function that calls another new
XMLHtttpRequest which is serviced by another php script that puts
the item's data back into a form in the 2nd div

The form contains data elements and a button to call a js script
to save the edited data.

That script fails because it can not find the form.

rather than copy the entire function I list only enough to show
the failure.
------------------------------
function saveItem () {
alert ("saveItem - entering 208")
alert ("saveItem - " +
document.getElementById("EditItemsForm"));

The both alerts are executed with the 2nd showing
"saveItem - " + null

If I change the EditItemsForm to another element that is not
dynamically generated it does not fail; it returns the id.

Thank you very much for taking the time to read this.
-bill

Re: AJAX scope problem

<si5c2m$1mn4$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17273&group=comp.lang.javascript#17273

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!5rX/CuUHQjLlpkAtZPIqeA.user.46.165.242.75.POSTED!not-for-mail
From: william@TechServSys.com (bill)
Newsgroups: comp.lang.javascript
Subject: Re: AJAX scope problem
Date: Sat, 18 Sep 2021 14:44:38 -0400
Organization: Aioe.org NNTP Server
Message-ID: <si5c2m$1mn4$1@gioia.aioe.org>
References: <si2ni7$1cge$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="56036"; posting-host="5rX/CuUHQjLlpkAtZPIqeA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: bill - Sat, 18 Sep 2021 18:44 UTC

I now define the form in the main part of the script, without any
input elements and then use the form attribute in the generated
part.

--
Bill Drescher
william {at} TechServSys {dot} com

Re: AJAX scope problem

<v8np847pdiq6$.1jf84awwlo2v0.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17275&group=comp.lang.javascript#17275

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!MFL9HJkb5TxOiTbNd+TBqw.user.46.165.242.91.POSTED!not-for-mail
From: jj4public@gmail.com (JJ)
Newsgroups: comp.lang.javascript
Subject: Re: AJAX scope problem
Date: Mon, 20 Sep 2021 22:14:28 +0700
Organization: Aioe.org NNTP Server
Message-ID: <v8np847pdiq6$.1jf84awwlo2v0.dlg@40tude.net>
References: <si2ni7$1cge$1@gioia.aioe.org> <1k6gcpx667ja9.1szyt9uqb1722$.dlg@40tude.net> <1v6fu43pso1x7$.1puo9tieoc9l3$.dlg@40tude.net> <si5apb$163a$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="16308"; posting-host="MFL9HJkb5TxOiTbNd+TBqw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: 40tude_Dialog/2.0.15.84
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Notice: Filtered by postfilter v. 0.9.2
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
 by: JJ - Mon, 20 Sep 2021 15:14 UTC

On Sat, 18 Sep 2021 14:22:35 -0400, bill wrote:
>
> If I change the EditItemsForm to another element that is not
> dynamically generated it does not fail; it returns the id.

Then the `getElementById` is called before the dynamically generated
`EditItemsForm` element is created and placed into the document. i.e.
`EditItemsForm` is called too soon.

The code which requires the element should be executed after the element has
been dynamically generated and placed into the document.


devel / comp.lang.javascript / AJAX scope problem

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor