Get selected jQuery id text code

In my form, I have several text fields like txtItemCode1 , txtItemCode2 , etc.

I use this code to perform some actions if I press the enter key for any of them, but I want to get the selected text field identifier. How can i do this?

+4
source share
2 answers

the id variable should have what you are looking for.

 $('input[type="text"]').change(function(){ var id = $(this).attr('id'); }); 
+9
source

In case you contacted your text field to perform input actions, use this to get the id entered text field.

 $(this).attr('id') 

or

 this.id 
+1
source

Source: https://habr.com/ru/post/1382408/


All Articles