I have an input box…
<input type="text" id="search_member" onkeyup="lookup(this.value);">
When I type in the field, it will go to function lookup(). From there I want to get the id of this input. I tried…
var This_id = $(this).attr("id");
but this won’t work. Any suggestions on how I can get the id?
Advertisement
Answer
Because you are passing this.value
to your lookup()
function. It’s better to pass this
to your function and then use arg.value
to get the value and arg.getAttribute('id')
for the id
<input type="text" id="search_member" onkeyup="lookup(this);"> function lookup(arg){ var id = arg.getAttribute('id'); var value = arg.value; // do your stuff }