-2

So, I have a little form input box, <input type ="text" /> and I can't seem to figure how to tell when it isn't being selected. Anyone know?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Ultimate
  • 3
  • 2
  • 2
    Seems you may need to clarify "selected" (probably the reason for the downvote); so far you have 2 answers offering different definitions – Dave Apr 07 '13 at 18:46
  • Please quickly explain what the aim of this exercise is? To not allow the user to leave the field unlike something entered? Do be careful of never ending loops when you focus on blur. Use setTimeout if necessary – mplungjan Apr 07 '13 at 19:11

2 Answers2

1

For a regular input, maybe the following was what you're after - jsFiddle here.

$(document).ready(function(){
  $('input').focusout(function(){
    alert('left input!');
  });
});
dsgriffin
  • 66,495
  • 17
  • 137
  • 137
0

There are a few things you could mean by "selected".

  1. Focus (whether the user has selected it, i.e. when they type it will change)

    var isFocussed = myInput.is(':focus');

  2. Checkbox being checked, in which case see zenith's answer

  3. Textbox with selected text, in which case look at this question: jQuery - How to get selected text from textarea/input?

Community
  • 1
  • 1
Dave
  • 44,275
  • 12
  • 65
  • 105