Reputation:
I want to call a javascript function on focusout
of a textbox. I have quite a lot of TextBoxes
so to prevent a listener for every TextBox
is there any possibility of calling the same javascript method on any textBox
focusout
passing the value of the Textbox as an parameter?
I want to do this on client side and not on server side.
Upvotes: 0
Views: 3514
Reputation: 537
The blur event occurs when the field loses focus.
Try this:
$("input").blur(function(){
//alert("ok")
});
Upvotes: 0
Reputation: 3356
Use
$("input").focusout(function(){
var tBval = $(this).val();
console.log(tBval);
// OR Call a function passing the value of text box as parameter
//myFunction(tBval);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
Upvotes: 0
Reputation: 37
With jQuery, it's as simple as
$("input").focusout(function(){
//Whatever you want
});
As pointed out by Milney, you probably want to interact with that specific textbox. To do this, you'd use "$(this)" as a selector.
$("input").focusout(function(){
$(this).css("background-color", "beige");
});
Upvotes: 1