Tuesday, December 22, 2009

Keep Focus on an Input Field in JavaScript

In my previous post, Handle Barcode Sacnner Input in Browser via jQuery, I use and input field to process the barcode read from scanner. One of inconvenience is, if the input field loses focus (which is happened a lot by incidentally mouse click), scanning will not work.

Therefore, it is better to keep the input field focused unless we finish scanning. To implement that, setInterval() can help us to do that by keep setting the input filed focused.

The javascript:


$().ready(function() {
var locked;

$("#lock").click(function(){

locked = window.setInterval(function(){
$("#focused").focus();}, 200);

});

$("#release").click(function(){
if(locked){
$("#focused").blur();
window.clearInterval(locked);
}
});

});




The html:



lock focus









Tuesday, December 1, 2009

Fixed width console in Eclipse

It is very helpful to set log4j's root level to "DEBUG" in order to find out problems. However, the consequence will be the endless moving horizontal scroll bar to read exception information in Eclipse.

With soar hands, I figured out to copy the exception into text editor, then enable "word wrap" at first. Then I realize how stupid I am to do so.

Eclipse supports "fixed width console". Right click on the console, "Preferences", check "Fixed width console". The default width is 80, in my mac book air, I double it, 160 is better when you maximize the console to read exception information.