Skip to main content
Known Participant
April 11, 2017
Answered

Difference between event.target.value vs. event.value

  • April 11, 2017
  • 1 reply
  • 22653 views

I can use event.target.value on the various mouse events, as well as the validate, calculate and format events.  However, with event.value I can use this only on the validate, calculate and format events.

For some reason, event.value does not work on the various mouse events.

1.  Why doesn't event.value work on the various mouse events?

2.  What is the difference between event.target.value and event.value?  Both refer to the value in the field whose properties window I am writing my code in.

3.  How do you know when to use event.target.value vs. event.value?

Correct answer try67

To summarize, event.value represents the field's new value, while event.target.value represents the field's current value.

The former is not available all the time, only in the events that were triggered by the change of the field's value, like Validation, Calculation, Format and Keystroke. The other events are triggered by the user interacting with the field in some other ways (entering it, exiting it, clicking it, etc.), and not by changing its value, which is why event.value doesn't exist for them.

This can be a bit confusing for some types of fields, like radio-buttons and check-boxes, where clicking them does change their values, and then event.target.value can return either the new value or the old one, depending on what triggered the event: Mouse Down will return the field's old value, while Mouse Up will return the new value, which was just applied to it by clicking it.

 

Knowing when to use either one is complicated and depends on your needs. You can read all about the event life-cycle and the meaning of the different types of events in the JavaScript for Acrobat API Reference, but the best way to learn it is through experience.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 11, 2017

To summarize, event.value represents the field's new value, while event.target.value represents the field's current value.

The former is not available all the time, only in the events that were triggered by the change of the field's value, like Validation, Calculation, Format and Keystroke. The other events are triggered by the user interacting with the field in some other ways (entering it, exiting it, clicking it, etc.), and not by changing its value, which is why event.value doesn't exist for them.

This can be a bit confusing for some types of fields, like radio-buttons and check-boxes, where clicking them does change their values, and then event.target.value can return either the new value or the old one, depending on what triggered the event: Mouse Down will return the field's old value, while Mouse Up will return the new value, which was just applied to it by clicking it.

 

Knowing when to use either one is complicated and depends on your needs. You can read all about the event life-cycle and the meaning of the different types of events in the JavaScript for Acrobat API Reference, but the best way to learn it is through experience.

Known Participant
April 12, 2017

Great explanation.  This really helps and it makes sense.  I reference the SDK PDF quite a bit but I can't always make sense out of it.  I do remember reading something that said what is returned by event.value depends on the event that is triggered or something to that effect.

I'll read over your reply a few more times and keep trying things.  Thank you very much.  This really clears up a lot of things for me.