Setting initial focus in html using Javascript - Pocket IE on Windows 2003 Pocket PC

Discussion in 'Javascript' started by dsnyder, Apr 12, 2004.

  1. dsnyder

    dsnyder Guest

    This HTML has a bit of Javascript at the end that puts the initial
    focus on the userID field. It works great on Windows2000 running IE6,
    but the initial focus never goes to the userID field on Windows 2003
    PocketPC (Windows Mobile) running Pocket IE.

    <html><head><title>WMS - P280WF100 - Login</title><META
    HTTP-EQUIV='expires' VALUE='0'>
    </head>
    <body>
    <form name="frmLogon" action='p280wp100' method='get'>
    <table>
    <tr>
    <td>User ID</td>
    <td>
    <input id='userID' name='userID'
    type='text'
    maxlength=10
    size=10
    >

    </input></td>
    </tr>
    <tr>
    <td>Password</td>
    <td>
    <input id='password' name='password'
    type='password'
    maxlength=10
    size=10
    >

    </input></td>
    </tr>

    <tr>
    <td colspan=2><center><input type='submit' accesskey='L'
    value='Login'></center></input></td>
    </tr>
    </table>
    </form>

    <hr>
    <script language=javascript>
    function window.onload(){window.frmLogon.userID.focus();}
    </script>
    </body></html>
     
    dsnyder, Apr 12, 2004
    #1
    1. Advertising

  2. dsnyder wrote:
    > This HTML has a bit of Javascript at the end that puts the initial
    > focus on the userID field. It works great on Windows2000 running IE6,
    > but the initial focus never goes to the userID field on Windows 2003
    > PocketPC (Windows Mobile) running Pocket IE.


    I have only had one short opportunity to examine a Pocket IE but it was
    rapidly obvious that it was not a cut down version of desktop IE (and
    not surprisingly so, as desktop IE is enormous). It seems likely that
    creating code to work on Pocket IE should be done following general
    cross-browser coding principles, so avoiding IE-isms and avoiding any
    reliance on the error correcting behaviour of desktop IE (best achieved
    by validateing HTML source code).

    <snip>
    > <input id='userID' name='userID'
    > type='text'
    > maxlength=10
    > size=10
    > >

    > </input></td>

    ^^^^^^^^
    Input elements are empty, they do not have a closing tag.

    <snip>
    > ... <center><input type='submit' accesskey='L'
    > value='Login'></center></input> ...


    The DOM created for scripting from HTML has a tree-like structure, and
    formally valid HTML also has a tree-like structure (allowing an easy
    translation from HTML into a DOM). But above you have and opening CENTER
    tag, and opening INPUT tag, a closing CENTER tag and then a closing
    INPUT tag. The closing INPUT tag is invalid anyway (as I mentioned
    above) but what is the browsers supposed to make of this strange
    overlapping of elements? Desktop IE error-corrects it (it has no choice
    as this is the sort of nonsense HTML that Microsoft Word outputs as a
    matter of course), but I am told that 50% of desktop IE's code is
    error-correcting and then will just not fit into Pocket IE.

    <snip>
    > <script language=javascript>


    Valid HTML 4 requires that script elements have a type attribute,
    rendering the language attribute redundant.

    <script type="text/javascript">

    > function window.onload(){window.frmLogon.userID.focus();}

    <snip>

    ECMA 262 (3rd edition) specifies a function declaration as having an
    identifier as a function name, not a property accessor. This is another
    IE-ism, and maybe Pocket IE does not understand it. Cross-browser code
    would assign a function expression to the - window.onload - property.

    Accessing named forms as properties of the global (window) object is not
    cross-browser either. Accessing forms as named members of the -
    document.forms - collection is the most widely (seemingly universally)
    supported mechanism available on HTML browsers.

    window.onload = function(){
    document.forms['frmLogon'].elements['userID'].focus();
    };

    Richard.
     
    Richard Cornford, Apr 14, 2004
    #2
    1. Advertising

  3. dsnyder

    David Snyder Guest

    Richard:

    Thanks for the info. I found this bit of code on this web site:
    http://www.htmlhelp.com/faq/html/all.html

    <script type='text/javascript'><!--
    document.frmLogon.userID.focus();
    //--></script>

    This seems to work in both of my environments and is closer to your
    example than my original code. I'll try your example and see how it
    goes.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    David Snyder, Apr 14, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Blake Versiga

    Setting Initial Focus on a Text Box

    Blake Versiga, Jul 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    397
    David Waz...
    Jul 3, 2003
  2. Brian Henry

    setting initial focus to textbox

    Brian Henry, Jul 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    548
    Craig Deelsnyder
    Jul 4, 2004
  3. Jason
    Replies:
    4
    Views:
    1,681
    Jason
    May 7, 2007
  4. Pierre
    Replies:
    0
    Views:
    203
    Pierre
    Nov 18, 2003
  5. Roger
    Replies:
    3
    Views:
    379
Loading...

Share This Page