×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    javascript set focus to input text box ??

    Hello all,

    I am developing a mobile site in Xhtml,CSS and (Ecma/Java)script
    for Nokia S60 3rd ed Fp2 emulator.

    The browser bundled with the emulator has a pointer arrow that you can move around and access fields on the page.

    However its a usability headache.
    The user always has to navigate to a text box and select it to input text. i need to set focus on an input text box when a page loads so that the user can immediately start entering the text.

    so i have this in my page :

    <script type="text/javascript">
    function setFocus(){
    document.getElementById("searchBox").focus();
    }
    </script>

    and

    <body onload="setFocus();">

    Its a pretty standard user requirement.

    It works fine if u try this in IE or FireFox.
    But this doesnt work in the emulator browser.
    The javascript does get executed.
    After the page loads the text box gets the focus but only for a brief moment after which it is lost again. I cant figure out why the focus is lost or which element gets it next?

    Is there a work around for this ? or maybe something very nokia specific that i have to do??

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Re: javascript set focus to input text box ??

    Hello,

    This does not work for the browser bundled with Nokia S60 3rd ed Fp1 emulator either. However the behaviour is different in this case. The javascript code is executed but it merely highlights the text box (draws a border around it).

    Has anybody come across this problem?

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Re: javascript set focus to input text box ??

    Hello All,

    Have i asked this question in the wrong forum by any chance?
    I am wondering bcos no one has replied whether they have faced
    this problem or a work around for it.
    Could some one please confirm that this is a issue and
    there is no work around for it as of now?

    Thank you.

  4. #4
    Regular Contributor
    Join Date
    Dec 2007
    Posts
    60

    Re: javascript set focus to input text box ??

    Quote Originally Posted by zaponjanx View Post
    Hello All,

    Have i asked this question in the wrong forum by any chance?
    I am wondering bcos no one has replied whether they have faced
    this problem or a work around for it.
    Could some one please confirm that this is a issue and
    there is no work around for it as of now?

    Thank you.
    While I haven't run into this in exactly the way that you are describing, I have noticed various issues regarding commanded focus in S60 widget development - especially in the tabbed navigation mode but also with the mouse pointer.

    A work-around that often helps a bit on the widget-side of things is to use a timer to command the focus after a short delay. That's not exactly an elegant solution but it seems to work in many situations.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    14

    Re: javascript set focus to input text box ??

    hi zaponjanx!
    i'm focusing exactly the same problem. i'm using 3rd ed. fp 1.
    i design my mobile web pages using xhtml and ecmascript. i use a <input> box (the same problem as with <textarea>) and can't get the cursor of the browser into the input box. i just can manage to get it highlighted (border around it), but this comes from the <body onload="focus();"> attribute in the html code.
    i tried different things in order to fill the input box with text:
    - implement OfferKeyEventL and pass all key events to my CBrCtlInterface object (iBrCtlInterface->OfferKeyEventL).
    - creating an instance of MBrCtlSoftkeysObserver class which gives a callback (UpdateSoftkeyL) if a softkey is pressed on an element (input box, button) of the webpage.
    - check the type of the focused element (iBrCtlInterface->FocusedElementType())
    and tell the browser control to activate the focused element:
    iBrCtlInterface->HandleCommandL(TBrCtlDefs::ECommandIdBase+TBrCtlDefs::ECommandOpen);
    this only causes another activation (highlight) of the input box but i can't fill it with text.

    there must be a way to tell the browser control to react on keyevents and fill text to input boxes, maybe i forgot to enable a setting or feature of the browser control...
    i tried other html elements (checkboxes, radiobuttons) which can be activated and selected without any problems.
    i also loaded my sample page in the native web browser of the emulator and text input works fine in that case. could it be a html/ecmascript-tag compatibility problem of the browser?
    maybe somebody has some hints on that issue...

    best regards,
    bernie

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Re: javascript set focus to input text box ??

    Hello bfamler,

    I am developing my app in pure XHTML MP / Ecmascript MP / WCSS.
    So using native platform browser control api is really not an option for me. Yes the behaviour u mention is the same as mine.
    I searched his topic in the bugzilla at webkit.org and found that this indeed is a reported bug. focus() to a text box does highlight the element but does not provide a carat in it for the user to start entering text. Using a timer as mentioned by "peppe@peppe.net" does not help either.

    This behaviour is common across platforms (s60,iphone,android) which use the webkit engine.

    So as of now i dont see a solution to this problem.

    Hope this helps.

Similar Threads

  1. Replies: 10
    Last Post: 2008-06-23, 11:28
  2. Set Default Values in Text Fields
    By Asif Nazir in forum Symbian User Interface
    Replies: 2
    Last Post: 2007-12-27, 06:27
  3. Replies: 0
    Last Post: 2004-11-24, 18:49
  4. How to check text input mode programmatically?
    By f6696 in forum Symbian C++
    Replies: 0
    Last Post: 2002-12-13, 06:13
  5. Howto set text of a form dynamicly?
    By pemag in forum Symbian C++
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •