Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #35950
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2019-01-02 14:14 -0800 |
| References | <ebbe3c4d-b24f-4c05-b30d-1963905dae45@googlegroups.com> <755ec860-e1c5-4f0c-bd13-0edcc7ae7d69@googlegroups.com> |
| Message-ID | <8eea4472-7224-4e44-a6f2-8ef930787eb5@googlegroups.com> (permalink) |
| Subject | Re: Not able to obtain any form objects |
| From | Dan Campbell <dcwhatthe@gmail.com> |
On Tuesday, January 1, 2019 at 7:12:49 AM UTC-5, Julio Di Egidio wrote: > On Tuesday, 1 January 2019 00:42:40 UTC+1, Dan Campbell wrote: > > > When the Javascript code is called, it doesn't seem to have access to any of > > the elements. > > Scripts execute immediately when encountered by the html parser (unless they > are marked async: I won't get into that). > > And your code is not wrapped in a function called e.g. on page load, > it just runs there and then. > > Now notice that you include your scripts before those elements are encountered > in the document, so those elements indeed do not exist yet at that point. > > All that said, an immediate fix, not to mention a best practice unless one > has solid reasons to do otherwise, is to include your scripts at the very > bottom of the page, just before the closing body tag. > > HTH, > > Julio Ugh. Forgot to throw in an Onclick event. I had stripped out everything from a longer example, and got rid of anything that would run the actual code. Anyway, after enclosing the script in a function and referencing it in the onclick event, it's working as expected. Thanks, Julio and Evertjan. Regards, DC
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Not able to obtain any form objects Dan Campbell <dcwhatthe@gmail.com> - 2018-12-31 15:42 -0800
Re: Not able to obtain any form objects "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-01-01 13:02 +0100
Re: Not able to obtain any form objects Julio Di Egidio <julio@diegidio.name> - 2019-01-01 04:12 -0800
Re: Not able to obtain any form objects Dan Campbell <dcwhatthe@gmail.com> - 2019-01-02 06:37 -0800
Re: Not able to obtain any form objects Dan Campbell <dcwhatthe@gmail.com> - 2019-01-02 14:14 -0800
csiph-web