Marco Grazia
Marco Grazia

Reputation: 57

Finding the form element that has focus

I would like to know, via javascript, which give a form element has the focus(), to be able to switch to a variable that holds the name of the currently active.

But without using frameworks like jQuery.

And without the use onfocus event within each component of the form.

Is that possible?

M.

Upvotes: 0

Views: 46

Answers (2)

KarthikManoharan
KarthikManoharan

Reputation: 805

try this code,

  document.formname.activeElement

As seen in this answer.

Upvotes: 0

xdazz
xdazz

Reputation: 160953

You could get it by:

document.activeElement

Upvotes: 1

Related Questions