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


Groups > comp.lang.javascript > #40388

AJAX scope problem

Path csiph.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.uzoreto.com!aioe.org!5rX/CuUHQjLlpkAtZPIqeA.user.46.165.242.75.POSTED!not-for-mail
From bill <william@TechServSys.com>
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> (permalink)
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
Xref csiph.com comp.lang.javascript:40388

Show key headers only | View raw


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

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

AJAX scope problem bill <william@TechServSys.com> - 2021-09-17 14:42 -0400
  Re: AJAX scope problem JJ <jj4public@gmail.com> - 2021-09-18 22:40 +0700
    Re: AJAX scope problem JJ <jj4public@gmail.com> - 2021-09-18 22:41 +0700
      Re: AJAX scope problem bill <william@TechServSys.com> - 2021-09-18 14:22 -0400
        Re: AJAX scope problem JJ <jj4public@gmail.com> - 2021-09-20 22:14 +0700
  Re: AJAX scope problem bill <william@TechServSys.com> - 2021-09-18 14:44 -0400

csiph-web