Kasun Wanniarachchi
Kasun Wanniarachchi

Reputation: 435

get selected textbox id jQuery

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

I use this code to perform some action if I press enter on any of these, but I want to get the selected textbox id. How can I do that?

Upvotes: 4

Views: 17042

Answers (2)

Jose Vega
Jose Vega

Reputation: 10258

variable id should have what you are looking for.

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

Upvotes: 10

Jeff Wilbert
Jeff Wilbert

Reputation: 4520

In the event that you have bound to your textbox's to perform actions on enter, use this to get the id of the textbox you pressed enter on.

$(this).attr('id')

or

this.id

Upvotes: 1

Related Questions