I am dynamically generating textboxes in ASP page and suppose they are calling javascript function “foo” on text change. I want to pass the textbox ID calling the function to that javascript function.
i.e. If you are typing in textbox 3, I wanna show that Currently You are typing in txtbox3 (the id of textbox 3)
I have an autocomplete function I dont know how to pass the ID of the calling textbox.. I am using class attribute but it changes the value of every textbox… I want the ID instead of .tbi
There are a couple answers depend upon how your code works.
If you are attaching the event handler with addEventListener, then you can get the object that generated the event from the
thispointer like this:or using a regular function:
or, if you are embedding the event handler directly in the HTML, you can do it like this:
As is usually the case on stackoverflow, if you show us your actual HTML and javascript, you will get answers specific to your particular situation.