The moose likes HTML, CSS and JavaScript and the fly likes Attach eventListener to objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Attach eventListener to objects" Watch "Attach eventListener to objects" New topic

Attach eventListener to objects

R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
Hi everybody,
I have this piece of code which calls the charCounter() function anytime user enters any letter in the input. Its working properly:

Now I am trying to mimc the above code, sending the title and left objects instead:

I have defined the following objects:

I think 'a' and 'b' are correct objects b/c a.value and b.value are the correct values, so I send the 'a' and 'b' objects to charCounter() function and expect the charCounter() function gets called anytime user
enters any letter in the Title or Left fields. Following is how I tried to attach the even listeners to the objects, also call the function.

How can I fix this?
R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
Some correction to the code! I modified the code as following; when the script executes for the first time, it gets inside charCounter() function and does calculate the remaining chars correctly, b/c I get:

TITLE: Auto Body and Paint
16 characters left

But then it does not do anything else as I type in Title field. So can you help me fix this in a way that does NOT go inside charCounter() when the script executes for the first time and instead gets in that function when user enters anything in the field?

wood burning stoves
subject: Attach eventListener to objects
Similar Threads
Uncaught TypeError: Cannot read property 'length' of undefined
Question on jQuery ajax functionality & troubleshooting called bean in JSF page
"Unterminated <c:out tag" Error
Calling a JavaScript function from within another JavaScript function
Need Help With Dynamic text box in JSP