Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Attach eventListener to objects

 
R Naijat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic