How to call a function after textbox lose focus
Solution 1
<input type="text" id="check">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$("#check").blur(function() {
alert('working');
});
</script>
Solution 2
Bind a handler to the change
event:
<textarea onchange='ajax_call()'></textarea>
where ajax_call
is a function for updating the DB.
Solution 3
Yes, you can. First you need to wait for JavaScript event like onchange/onblur or other. Than you need to make an Ajax call to the server. It will change the data in db and can result some data, that you can put on the page. You can use jQuery to manipulate your page.
Another way is to wait until a person presses submit button and than update data in the db.
Related videos on Youtube
Wallkan
Hello, I'm a BigData engineer that works mainly on Scala, but I've worked also with Java EE, Javascript/HTML/CSS, Flex, C/C++ and C#.
Updated on July 09, 2022Comments
-
Wallkan almost 2 years
I have no experience with Javascript/JQuery/AJAX so I'm trying to understand if it's possible to call a function that execute a query on my DB after a textbox lose focus.
I'm displaying a table in my page (using PHP) with text boxes that contains the same values of a table on my DB, and when someone change the value on a text box I want to change the DB table with an UPDATE query to make them equals; is that a way with AJAX or JQuery to do this?
-
Felix Kling almost 12 yearsJust clarify some things: JavaScript is a language, jQuery is a library written in JavaScript and Ajax is method of communication. Maybe you find the MDN JavaScript Guide helpful.
-
-
Jashwant almost 12 yearsYes, its year 2012 and I just saw an inline js.
-
spaceman12 almost 12 yearsits not that i dont know about the advanced method available but with a novice, i prefer to used the simplest one availble! Maybe, it's you who should realize its 2012
-
Jashwant almost 12 yearsThat was a lite joke bro. Keep it cool. But may be you dont realize that your method works on
onchange
not on losingfocus
as OP wanted :) -
eaglei22 over 7 yearsit's 2017 and I am still using inline JS function calls.. and still see nothing wrong with it. Or maybe it's 2012 for whoever is reading this and this is me from the future.