Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In which TextBox is the cursor.?

I have 4 textboxes and a submit button in my web page. Suppose the user enters data in 2 fields and then clicks the submit button. I now want to know in which textbox the cursor was located just before the submit button was clicked.

Any idea on how to do this in Javascript?

like image 754
Pradeep Avatar asked Mar 22 '23 14:03

Pradeep


1 Answers

You're looking for document.activeElement, which returns the currently focused element.

like image 128
SLaks Avatar answered Mar 31 '23 23:03

SLaks