Opera Mobile 9.7 Beta Set Focus [duplicate]
Asked Answered
C

1

2

We use a handheld scanner to move items in and out of inventory. The scanner runs an ASP page that submits the form to move the item. We recently purchased a new scanner running Windows Mobile 6.1 and soon realized that Mobile IE is completely useless. It does not render tables correctly and worse, it doesn't recognize onblur, onkeypress and many other common javascript functions.

We tested out many mobile browsers and found that Opera Mobile 9.7 works great except for setting the focus on an input text field when the page loads. The page has many text fields that and submits the form back to itself for processing. Once one field is scanned (or entered on the keyboard), the form submits itself, process the input and enables the next field on the form. At the end of the markup, select() and focus() are called to select any text in the field and to set focus so all the user has to do is scan the value. Here is what the javascript looks like at the end of the page.

document.forms["frm1"].elements["txt1"].select(); document.forms["frm1"].elements["txt1"].focus();

Is there any way to set focus on Opera Mobile 9.7?

Comminute answered 28/9, 2009 at 18:45 Comment(4)
Have you tried wrapping those 2 lines in a setTimeout with short delay?Balenciaga
I tried your solution, but it doesn't work. When I wrap it in setTimeout the select() method doesn't work either. The focus() and select() methods are defined, because if I put alert(document.forms["frm1"].elements["txt1"].focus); it tells me it is a method.Comminute
This is strange. The only other "fix" I can think of is to add explicit tabIndex to input element (tabIndex="-1", for example). If that doesn't work, it might very well be that Opera does not support programmatic focus.Balenciaga
It looks like the focus() method is not working. If I call select(), the onselect event is fired, but if I call focus(), the onfocus event is never fired. I filed a bug with Opera.Comminute
M
1

You can use autofocus for the input field in Opera 9.7 like this: <input type="text" autofocus />

However, that only seems to work on the first load, after submitting the form the field loses focus again. Please let me know if you find a solution.

Mongolic answered 21/10, 2009 at 9:18 Comment(1)
this doesnt work in Opera Mobile 10 !(and i don't know how to find 9.7 :( )Jaret

© 2022 - 2024 — McMap. All rights reserved.