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


Groups > comp.lang.javascript > #40388

AJAX scope problem

From bill <william@TechServSys.com>
Newsgroups comp.lang.javascript
Subject AJAX scope problem
Date 2021-09-17 14:42 -0400
Organization Aioe.org NNTP Server
Message-ID <si2ni7$1cge$1@gioia.aioe.org> (permalink)

Show all headers | 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