0

Could you suggest the best way to keep focus on a particular input field on page? What I am trying to say is, no matter where user clicks on the screen, the focus should return back to this one particular input. I am thinking of a timer function that would check for focus every 500ms and if its not there, then bring it back. Also the best way to submit this input field without making use of any button Any other and best solution for this?

greg0ire
  • 22,714
  • 16
  • 72
  • 101
t0mcat
  • 5,511
  • 19
  • 45
  • 58

2 Answers2

2

Even if I don't like the idea, thinking about usability and user experience. Anyway, to answer your question, your best shot probably is to set the focus initially to that input element and watch for the blur event. Addionally you might want to check for outside click events.

That might look like this:

$('#test').bind('focusout', function(e) {
    if($(this).val() !== 'releaseme') {
        setTimeout(function() {
           $(e.target).focus();
       }, 25);
    }
});

That would force the focus to that input (with the ID "test") 25ms after it lost the focus. To check for the additional outside-click check this link.

Example link: http://www.jsfiddle.net/FX79h/

Again, this sounds not usefriendly. You might want to think about whatever you are trying to do.

Community
  • 1
  • 1
jAndy
  • 231,737
  • 57
  • 305
  • 359
  • Hi Andy, Could you please tell me why you think this is not user friendly? Actually I have to pass this input to server using an ajax call but user cannot invoke this call, as soon as input field gets filled, I need to make a call – t0mcat Sep 17 '10 at 16:18
  • 1
    @t3ch can you imagine trying to read a page while the focus is routinely shifted away? Also if you have any other fields on the page, users would never be able to enter anything into them because the focus would immediately be stolen. – Daniel Vandersluis Sep 17 '10 at 16:22
  • 1
    @t3ch: I'm afraid I don't understand what you mean. Your initial question was about prism the user into a specific input element (which is bad because an user does not expect such a behavior, how would he?). Your comment now sounds a lot different. If you just need to know when something was entered in that `input element`, you might just want to listen on the `keypress` event and continue from there. – jAndy Sep 17 '10 at 16:22
  • 1
    In other words, please don't do this. :) – Daniel Vandersluis Sep 17 '10 at 16:22
  • Thanks andy, there wont be any other input fields on the page, just few buttons which have there own event handlers. – t0mcat Sep 17 '10 at 16:25
  • 1
    This is still a terrible user experience. You're breaking all of the user's expectations as to how the web should behave, and will frustrate him to no end. Why can't you just wait until the user presses enter, or a button, or even stops typing for 3 seconds after he starts typing, before submitting the field with Ajax? – Domenic Sep 17 '10 at 16:32
  • This input would be fed from scanner. – t0mcat Sep 17 '10 at 18:01
0

Would be a major impediment to disabled accessibility consideration. Remember, some people don't use mice to navigate, and you'd render the site useless to them.

As to allowing submit, you could trap the enter keystroke via Javascript...there's several tutorials on how to do it. However, this would also negatively affect the expected user interaction pattern and disrupt accessibility aids. The button text is the only thing telling a blind user's screen reader that they can submit to the site. Without it, your site is a black hole to them.

I'm all for experimentation and pushing the envelope, but there are reasons that you see so many common elements across the web. Think about it like this--would you stop for a triangular blue stopsign? How about a square pink one? Believe it or not, familiar patterns make for a more comfortable experience. How you "push" familiarity is what determines your success as a UI person. I might add that there's a LOT of bad UI out there....

bpeterson76
  • 12,918
  • 5
  • 49
  • 82
  • Hi bpeterson, this input is going to be fed from a scanner and user has no control on the page what so ever – t0mcat Sep 17 '10 at 18:02