Announcement Announcement Module
No announcement yet.
Defaultiing the focus to the first text field in IE Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Defaultiing the focus to the first text field in IE

    The Roo-scaffolded views use Dojo decorations for HTML form fields such as text fields, text areas, and select lists. I have a requirement that if any page has a text field on it, the focus should default to that field, so that the user can start typing straight away without having to click into it with their mouse (or use the Tab key).

    I've tried adding this script to the end of my default.jspx file, just inside the closing body tag:

    <script type="text/javascript"><![CDATA[
                    function() {
                        // Set the focus to the first editable field in the 1st form
                        var formElements = document.forms[0].elements;
                        for (var i = 0; i < formElements.length; i++) {
                            var formElement = formElements[i]; 
                            if (formElement.type == 'text') {
    This works fine in Firefox, as follows:
    ... but not in IE8 (the main target browser for this app), where the first text field gets a different outline to the others, but doesn't accept keyboard input:
    If I click in it or tab to it, it works like normal, but that defeats the purpose.

    Does anyone know how to properly give the focus to a Dojo-decorated text field?