/    Sign up×
Community /Pin to ProfileBookmark

document.getElementById(…) is null or not an object

I am new to php and AJAX, and I’m stuck. I am developing a webpage that uses two html forms, each onsubmit references a javascript, the scripts for each are stored in two separate .js files that are listed in the header of the html file as such..

The code for each respective .js file, are very similar but I changed the name of the global variables and the function names because I read that could be the problem. No matter what I do I still get the same error, the first form runs, uses the javascript which then calls a .php file with code that connects to an Oracle database runs a query and returns the info back to the html page in a placeholder variable called txtMnemonics, this one works fine. If you run the second form, which does the same things but uses a different js file and calls a different .php file for a different query, I get the following error:

document.getElementById(…) is null or not an object

I have attached the related files for review, if anyone can help sort this out that would be great.

Jon

[upl-file uuid=eaa4067f-70e8-4d28-bbfd-458fd3d00bb3 size=3kB]javascript_issue.txt[/upl-file]

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@mataichiJun 30.2009 — Inf Form 2, I do not see that you closed the select tag. You need to add </select> before the </form>.

This may be causing the problem.
Copy linkTweet thisAlerts:
@jgrimm5authorJun 30.2009 — I knew it was something simple that I just overlooked. This was a result of alot of copy and pasting and making changes. Somehow I missed closing the </select>, thanks again!

Nice to have a new set of eyes sometimes!!

Jon
Copy linkTweet thisAlerts:
@mataichiJun 30.2009 — We've all been there.
Copy linkTweet thisAlerts:
@jgrimm5authorJun 30.2009 — Since you were so helpful, the last thing I can't figure out is how to change both those forms to be input text boxes, and pass that to the js and php, instead of having the drop down list.

Any idea how the syntax would be for that?

I have tried a few things like this but I either get an error or nothing comes back.

<form>

Mnemonic Code:

<input type="text" name="mnemonic" onchange="showUser(mnemonic)" />

<input type="submit" value="Submit" />


</form>
Copy linkTweet thisAlerts:
@mataichiJun 30.2009 — Well, you want to pass a value to showUser(). The way you have it setup you are passing a variable that has no value. Do you mean to put showUser('mnemonic')?

Or why not use this.value as you did before? showUser(this.value)?

Also, when do you want the event to fire? After each key stroke or perhaps onblur (when the focus is removed from the text box)?
Copy linkTweet thisAlerts:
@jgrimm5authorJun 30.2009 — I have it like this now, I like the onblur option because if I have onsubmit when you click submit the entire page seems to refresh and wipes out the other form results which is the whole reason I changes it. Now the problem still is it passes what I type in at least it appears too such as DRUS but no resutls come back. The error I get is "Object expected" the URL shows as http://bjp0jh1/security_test/index.php?mnemonic=DRUS which is what leads me to believe the variable value is passed to the javascript?


<input type="text" name="mnemonic" onblur="showUser(this.value)" />

The probl
Copy linkTweet thisAlerts:
@jgrimm5authorJun 30.2009 — never mind, I figured it out. ?
Copy linkTweet thisAlerts:
@mataichiJun 30.2009 — What was the solution so others will know too.
Copy linkTweet thisAlerts:
@jgrimm5authorJun 30.2009 — The way it is above is perfect you just have to call the right function name. So both work now just fine.
×

Success!

Help @jgrimm5 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...