Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16391
| From | Gregor Kofler <usenet@gregorkofler.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: event listener |
| Date | 2012-10-04 14:07 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <k4ju6d$ntp$3@dont-email.me> (permalink) |
| References | <7000beba-a8d0-48f9-a446-7f7849e981a8@googlegroups.com> |
Am 2012-10-04 13:49, michal meinte:
> Hello,
> Could someone help me find problem with event handler on dynamically
created input tag. here is code
>
> var bod = document.getElementById("body");
Is this smart? An element with id "body"?
> var par = document.createElement("p");
> bod.appendChild(par);
> var txt = document.createTextNode("text 1:");
> par.appendChild(txt);
> var inp = document.createElement("input");
> par.appendChild(inp);
> inp.addEventListener('change',alert("dfd"));
>
> Last line is most important here. I assumed that alert window is
triggered ones text is changed in input field but NO this alert is
triggered immediately after listener is added and after that don't work
I mean don't rise even if text is changed in input field.
> What is wrong, how to add listener to input field.
Correct:
inp.addEventListener("change", function() { window.alert("dfd"); });
In your case you the *return value* of the alert() call becomes the
addEventListener() argument.
Gregor
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
event listener michal <michal.otawa@gmail.com> - 2012-10-04 04:49 -0700
Re: event listener Martin Honnen <mahotrash@yahoo.de> - 2012-10-04 14:03 +0200
Re: event listener michal <michal.otawa@gmail.com> - 2012-10-04 05:22 -0700
Re: event listener Gregor Kofler <usenet@gregorkofler.com> - 2012-10-04 14:07 +0200
csiph-web