I have 4 textboxes and a submit button in my webpage 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..??
you can use document.activeElement
here is the simple example for the same.
You're looking for
document.activeElement
, which returns the currently focused element.Your question does specifically say in javascript, but FWIW here is another option in jQuery:
Working jsFiddle here
HTML:
jQuery: