Setting .focus on first input field

I sometimes run into situations where Mendix will not set autofocus to the first input field automatically.  This happens mainly in full-page forms (pop-ups are usually fine) and may be due to styling.   Regardless; I figured I should be able to resolve it quite easily with a bit of javascript, so I threw a couple of code snippets at it through the browser console by way of test, but to no avail.  $(".FirstFocus").focus(); or  $(".FirstFocus:first").focus();  where FirstFocus is the class of the input field, both yield an output in the console: [, prevObject: jQuery.fn.init(1), context: document, selector: ".FirstFocus:first"]  and TextInput_16 is indeed the ID of the field I'm trying to set focus on. However, no focus is set.   My guess is I'm overlooking something dead obvious, but I rarely mess around much with the Mx frontend in this way. Anyone with a push in the right direction? 
5 answers

This is the JavaScript we're using to set the focus on an input field when loading a form:


$('.activetextbox input').focus();

As you might see, our textbox has the .activetextbox class


@Paul: Your snippet shift focus to the top of the page (if I scroll down first, and then fire the command from the browser console), so it's having an effect. Still no focus on the field though.

I'm starting to get the impression that something on the page is interfering, but I'm not yet sure what. Will run further tests.



What I've got so far:

When the page is opened and the input field is still empty, focus is set to the first input field (by Mendix, even without script).

When the page is opened and the input field has contents, no focus is set. If I try to set focus to the first field using javascript, it does move the page back up to put the field in view (if needed), but nothing more.

It doesn't seem logical that the input field having contents should prevent .focus() from working (can't find any info to that effect), but so far it seems the only difference.



I think it would be a great improvement to automatically set the initial focus to the component having the tab index set to 0.



is the focus helper an option?