Databases - Delphi/WebServers - Controlling the Input Focus

I have html pages that recieve data from a portable barcode reader. For these to work, the input focus must be the barcode entry field. In general, I hate JavaScript, but that is the only way to keep the input focus on the barcode input field.

Barcode Entry Field | Setting the default input field | focus()

Barcode Entry Field

This defines the barcode entry field.

Setting the default input field

This code moves the cursor to the default input field - useful when the form's primary input is a barcode reader.

Unfortunately, this code has a small problem. The portable barcode reader I am using turns off the backlight after a few seconds. One way to turn it back on is to tap the touch sensitive screen ... which causes the input field to loose focus. The following code "fixes" this problem by simply moving the input focus back to the barcode field every second.

Experimentation proves that setTimeout causes the timer to fire only once for each time it is set. As a result, the timer must be set each time SetFocus is called. setInterval continues to call the target function every n milliseconds until the program stops. I don't think that StopTimer is nedded.

Note that SetFocus has to be either defined or called after the form definition is complete. In IE, the OnLoad body parameter is executed as soon as possible, not after the load is complete. (Kind of defeats the purpose.)


Originally, I implemented these functions using focus()

Initially, it worked fine ... but as testing continued

setActive solved both of these problems.

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Databases / Delphi / WebServers / WebServer_InputFocus.html