Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send ajax request when textfield's OnBlur event is fired

Is is possible to use AJAX on an onblur event from a textfield. I'd like html (inside a div container) to change whenever I tab out of a textfield. I see a lot of questions/tutorials using AJAX with forms but not on the individual components such as textfield or checkbox.

like image 229
user1665112 Avatar asked Dec 21 '22 16:12

user1665112


1 Answers

You can do it using plain JQuery. Assuming your form element has the ID of my_element:

$("#my_element").blur(function(){
  $.ajax({url: '/my/data', type: 'GET'})
  .done(function(response){
    $("#my_div").html(response);
  })
})
like image 61
Erez Rabih Avatar answered Jan 02 '23 16:01

Erez Rabih