Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 1.24 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. detect barcode reader input
  2. $("#barcode_form").click(function(){
  3.   var focusedElement = "";
  4.   $(":focus").each(function(){  
  5.     focusedElement = $(this).attr("id")                
  6.   });
  7.   if(focusedElement == ""){
  8.     $('#text2display').focus()
  9.   }
  10. })
  11.        
  12. if(focusedElement == ""){
  13.   //if our focused element is empty
  14.   $('#text2display').live('blur', function(){
  15.     //when the target loses focus, we invoke blur, the next line focuses again.
  16.     //it's also a best practice to do something like fading in the border,
  17.     $("#text2display").focus();
  18.   });
  19. }
  20.        
  21. if(focusedElement == ""){
  22.   //if our focused element is empty
  23.   $('#text2display').live('blur', function(){
  24.     //when the target loses focus, we invoke blur, the next line focuses again.
  25.     //it's also a best practice to do something like fading in the border,
  26.     $("#text2display").focus(function(){
  27.       $(this).animate({
  28.         //when the element has been re-focused, we'll give it a red border briefly.
  29.         borderColor: '#ff0000';
  30.       }, function(){
  31.            //once the animation completes, fade the border out                    
  32.            $(this).animate({ borderColor: 'transparent' }, 2000);
  33.         }
  34.       );
  35.     });
  36.   });
  37. }
  38.        
  39. input{
  40.   border:1px solid transparent;
  41. }