/    Sign up×
Community /Pin to ProfileBookmark

Problem with addEventListener

I’m trying to add an event listener to an input element within a table and am having trouble getting it to work.

[Code]
10 function coordChange (event)
11 {
12 …
13 }

50 row1 = document.createElement (“tr”);
51 latCell = document.createElement (“td”);
52 latCell.appendChild (document.createElement (“input”));
53 latCell.type = “text”;
54 latCell.name = “pointLat”;
55 latCell.id = “pointLat”;
56 var pointLat = document.getElementById (“pointLat”);
57 pointLat.addEventListener (“change”, coordChange, false);
[/code]

It’s a pretty round abound way to get the <input> element, but every other way I tried:

[Code]
pointLat = document.createElement (“input”);
pointLat.addEventListener (“change”, coordChange, false);
[/code]

For example, IE told me that the method or property for pointLat was undefined (or something like that).

But, back to the code I have now, when I try to work my page and JavaScript on IE, I get the following:

[Code]
Message: ‘null’ is null or not any object
Line: 57
Char: 7
Code: 0
URI: file://…/myJavascript.js
[/code]

Any ideas on what I’m doing wrong?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mityaDec 09.2009 — addEventListener is non-IE only.

For IE use attachEvent (which takes 2 args, not 3 - you can't control bubbling)
Copy linkTweet thisAlerts:
@TimAndersonauthorDec 10.2009 — Thanks. That did it. (I really do hate the way that IE does everything different).:mad:

But anyway, would the IE thing also have something to do with my <select> name not getting passed to my servlet?

[CODE]
<form name="mainForm" method="GET" action="http://localhost:8080/ImageSearch">
<p>
Query Method:
<select name="queryType" onchange="queryTypeChange(this)">
<option value="NONE">Please Select a Query Method...
<option value="POINT">Single Point
<option value="RECTANGLE">Rectangle
<option value="ALL">All Images
</select>
</p>
<p>
<!-- Some other form inputs that are being passed on "Submit" -->
</p>
<input type="submit" value="Submit">
</form>
[/CODE]
×

Success!

Help @TimAnderson 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.18,
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,
)...