execute script automatically

0

How can I execute this script below, when the input label is filled in?

<script>
$(document).ready(function(){
    var serie = $('#serie_maquina').val();
    var grupo = $('#grupo_maquina').val();
    console.log(serie);
    console.log(grupo);
    $.ajax({
        type:'post',
        url: 'info_maquina_consulta.php',
        data: {
            'serie':serie,
            'grupo':grupo
        },
        erro: function(){
            alert('erro');
        },
        success: function(data){
            $("#maquina_carrega").html(data);
        }

    });
});

EDIT1 follow html as requested:

<form>
    <div class="col-sm-6">
        <div class="input-group input-group-md">
            <span class="input-group-addon" id="sizing-addon1">Numero Serie</span>
            <input type="text" class="form-control" name="serie_maquina" id="serie_maquina">
        </div>
    </div>
    <div class="col-sm-6">
        <div class="input-group input-group-md">
            <span class="input-group-addon" id="sizing-addon1">Modelo</span>
            <input type="text" class="form-control" name="grupo_maquina" id="grupo_maquina">
        </div>
    </div>
    <button id="btn_consulta" type="button" class="btn btn-md btn-success">Pesquisar</button>
</form>
    
asked by anonymous 11.04.2018 / 20:31

1 answer

0

You can use the focusout event to run as soon as the input is filled and lose focus

$('#inputId').on('focusout', function() {
    //código a ser executado
});

or use keyup which always executes when a key is pressed and returns to its original position, causing the script to run at the same time that something is typed in the input

$('#inputId').on('keyup', function() {
    //código a ser executado
});
    
12.04.2018 / 14:54