How to do to one or more field within the screen execute javascript function

0

I have a javascript function that should be executed when any of the two fields are made any kind of change.

At first only the #DataAbate field when a change is performed runs the script but I want the #AntiValue to also execute the function.

The question is how to make #DataAbate and #AntiValue without code redundancy.

 $(document).ready(function () {
   $("#DataAbate").change(function () {
   $("#SequenciaInicial").empty();
   $("#SequenciaFinal").empty();
   $.ajax({
            type: 'POST',
            url: '@Url.Action("GetSequencia")',
            dataType: 'json',
            data: { dataAbate: $("#DataAbate").val() },
            success: function (data) {
                $.each(data, function (i, data) {

                    document.getElementById('NumeroLote').value = parseInt(data.NumeroLote) + 1;
                    document.getElementById('SequenciaInicial').value = parseInt(data.SequenciaFinal) + 1;
                    document.getElementById('SequenciaFinal').value = parseInt(data.SequenciaFinal) + parseInt($("#QuantidadeAnimais").val());
                });
            },
            error: function (ex) {
                alert('Falha ao buscar Proprietario.' + ex);
            }
        });
        return false;
    })
 )}
    
asked by anonymous 14.03.2018 / 23:02

1 answer

1

1 -

To shoot with two different id's:

$("#DataAbate, #QuantidadeAnimais").change(function () {
//seu codigo
})

Or with classnames:

$(".classnameEmComumEntreOsCampos").change(function () {
//seu codigo
})

2 -

To add a direct classname to HTML:

<elemento class="classname"></elemento>

Or to add the classname via jQuery:

$("#DataAbate, #QuantidadeAnimais").addClass('NomeDoClassname');
    
14.03.2018 / 23:31