jQuery stay focused!
June 6th, 2008
Filed under: Food for thought
This is really just something for all you new jQuery learners, if you want to keep the cursor inside of a text box, even if you click elsewhere on the page, you can do this:
//Initial focus on #inputfieldid
$(”#inputfieldid”).focus();
//When you click anywhere it focuses back on #inputfieldid
$(this).click(function(){
$(”#inputfieldid”).focus();
});








December 29th, 2008 at 7:31 pm
Then you’ll never be able to click away from the input field. How is that even useful?
December 29th, 2008 at 7:58 pm
But that’s the idea of the script… I used this script when writing an online inventory management system for VTTI. It locked the cursor to an input field when a user had to stop and use a bar code gun to scan items into the input field.
If you click any link it will take you to that page, it would require a “return false” statement to cancel that.