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?
Asked
Active
Viewed 385 times
-2
-
2Seems 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 Answers
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
-
-
-
-
1Yeah, that works, but when I try to get it to work (Trying to get it to reselect a input after they deselected) it completely doesn't work. – Ultimate Apr 07 '13 at 19:03
-
1@Ultimate How doesn't it? It fires every time the input is left in the jsFiddle correctly, just like your question asks – dsgriffin Apr 07 '13 at 19:05
-
Yeah but for my code it isn't working...well, I'll give you the answer, I probably have some code undoing it. – Ultimate Apr 07 '13 at 19:15
-
@Ultimate That's cool, you're one step closer - maybe post a new question with more of your code for the new problem, I am sure many people will want to help – dsgriffin Apr 07 '13 at 19:16
-
Well, here's a example where it is not working. http://jsfiddle.net/MrPsau/tVgHJ/ When I deselect the input box, it should reselect it. But it does not. – Ultimate Apr 10 '13 at 01:40
0
There are a few things you could mean by "selected".
Focus (whether the user has selected it, i.e. when they type it will change)
var isFocussed = myInput.is(':focus');
Checkbox being checked, in which case see zenith's answer
Textbox with selected text, in which case look at this question: jQuery - How to get selected text from textarea/input?