Forum Moderators: open

Message Too Old, No Replies

Forcing a Field to Lose Focus

Sending special chars - force a tab after input?

         

txbakers

8:18 pm on Oct 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to implement an onChange event in a text box, but I can't figure out how to force the textbox to lose focus.

This is for a barcode application. The user scans a code and as soon as the box is filled, the event should fire. I'd rather not have to have the user click a "Go" button each time.

The onChange event works fine, but the textbox containing the data needs to lose focus first. I thought about sending a "tab" ANSI character in with the barcode, but I can't find the entity number for it yet.

Any ideas on how to force an element to lose focus without a click or keyboard input?

Thanks.

starway

6:47 am on Oct 7, 2002 (gmt 0)

10+ Year Member



In order to force an element to lose focus you can use this:
document.formName.fieldName.blur();

But I'd rather do another thing: instead of just moving focus away (to "nowhere", when the result can be unpredicted), I'd set the focus to some other element:
<input type=text ... onchange="... ;document.formName.anotherFieldName.focus();">