PDA

View Full Version : It's possible to know the field that holds the focus before button click?



sergiomichels
3 Jul 2013, 12:54 PM
In a form, that have a couple of text items and a button, it's possible to know in witch item the focus was before the click in the button?

I want to open another form, in a button click, and this form have a "context" that depends in the focus of the previous form.

Any thoughts?

slemmon
4 Jul 2013, 3:58 PM
There's not a property that shows the last focused item in a form and there's not a beforeclick type event where you could look for the actively focused item.

So, you'll need to listen to the focus events fired on each field and record which one was focused last and then refer to that value when the button is clicked.

sergiomichels
5 Jul 2013, 4:06 AM
I used the blur event to that. In IE there's a little delay in this, so I used setTimeout also. More info here (http://stackoverflow.com/questions/17457903/its-possible-to-know-the-field-that-holds-the-focus-before-button-click).