I have a page in a site that contains an iframe with a form in it. I can't change this but I do have full control over all of the JS that runs in the parent page and the iframe'd page.
My problem is that when I have a form field focused in the iframe'd document, tabbing to the next field sends the cursor straight up to the address bar of the browser, not the next field in the form. Setting tabindexes on each of the fields doesn't help.
The browser is treating the entire iframe itself as one of the elements in the page (as it should), but I'm wondering if there's a way to capture the tab events and force focus to stay inside of the iframe and with its child elements.
Have any of you run into this issue before and have a way around it?
Not that it will help you, but the layout is something like:
+-------------------------------------------+
| Parent page |
| +-------------------------------+ |
| N | iframe | |
| a | | |
| v | Has about 50 fields that I'd | |
| i | like to be able to tab between| |
| g | | |
| a | But I can't! Help! | |
| t | | |
| i +-------------------------------+ |
| o |
| n |
+-------------------------------------------+
One idea was to try and capture the keydown events in the iframe, check for tab or shift+tab and then refocus the iframe, but then there's the problem of knowing which field I was on before losing focus. Is there a way to dynamically focus the next field using JS and the tabindex attribute on the form fields? Perhaps that's where I venture next...
Update: perhaps there's something even simpler that I'm missing. For example, the login box on http://www.studentloan.com is an iframe and I can tab between those fields just fine. Maybe something else in my JS is causing the problem.
Update 2: I tried loading just the iframe document in the browser as a standalone page and I still can't tab. I think it's something I'm doing in JS somewhere else that's causing the document to lose focus. I'll post my solution when I find it.
Thanks!