how to get the value from an event target in js
Asked Answered
C

3

13

inside js function I'm receiving event as parameter, how do you get the value of the event target?

function myFn(event){
    ...
    close: function(event){
        var myVal = ... 
        /// should grab from 
        /// event-> arguments -> [0]->target -> property value painted in yellow (abc)        
    }
}

enter image description here

Callas answered 13/7, 2016 at 9:52 Comment(3)
What is the question?Trichomonad
How is myFn invoked?Levins
I though it was obvius that I need to get abc value from highlighted part of the image, mentioned on the comment also.Callas
B
39

Try:

var myVal = event.target.value;
Bedpost answered 13/7, 2016 at 9:54 Comment(5)
Despite the lack of clarity in the question. I think this is the answer the OP is looking for.Trichomonad
Thanks this partially solves the problem, if I type fast enough myVal gets populated with first 4,5 letter, after that it stays on that no matter what I type afterwards. But if I wait couple of seconds then it updates the values again.Callas
@Callas What event listener are you using?Kibe
Spent two hours in jQuery only to find that the solution is that simple.Preset
probably using onChange event, you need onInputChristiniachristis
C
1

This will work:

(<HTMLInputElement>event.target).value

or

event.target as HtmlInputlement

Cableway answered 3/6, 2020 at 19:19 Comment(0)
G
0

Try:

function($event) {
  const value = $event.target.value;
  ...
}
Gintz answered 27/4, 2021 at 12:2 Comment(1)
you can use event.target.getAttribute('value')Madriene

© 2022 - 2024 — McMap. All rights reserved.