Change "on" to "click" in JavaScript function

2

I want when I click on the radios to call the function, it is currently like this.

$("input[name='txtCategoria']").on('blur', function(){
    var txtCategoria = $(this).val();
    $.get('buscar_tipos.php?txtCategoria=' + txtCategoria,function(data){
        $('#tipos').html(data);
    });
});

But when I click on the radio and click on another part of the page that appears the query, I wanted it to click once it is executed, so I tried.

$("input[name='txtCategoria']").on("click", function(){
    var txtCategoria = $(this).val();
    $.get('buscar_tipos.php?txtCategoria=' + txtCategoria,function(data){
        $('#tipos').html(data);
    });
});

But it did not work, could anyone help me?

    
asked by anonymous 25.03.2017 / 16:19

1 answer

3

blur means "when the element loses focus" . This is what happens when you click out of this element, and the function runs. Because it "lost focus."

The most semantic would be change , which is when% % change in value. So, even for those who navigate and change the input with the keyboard, the logic will work.

$("input[name='txtCategoria']").on("change", function() {
  $.get('buscar_tipos.php?txtCategoria=' + this.value, function(data) {
    $('#tipos').html(data);
  });
});
    
25.03.2017 / 16:22