I am trying to pass an element through my function and output the id.
Here is what I mean:
<input id='password' style="display:inline-block" type="password" name='Password' onKeyDown="setTimeout('validate(this)', 10)" />
and the javascript:
var validate = function(element)
{
alert(element.id);
}
Is this the correct way to do the following? All I get is undefined when it alerts. Thank you.
When called from the
setTimeoutfunction, thethispointer is no longer pointing to the input element, rather it is pointing to thewindowobject.What you can do is
Or better yet:
and on the element: