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 field #Dating when a change is performed executes the script but I want the #Quantidadeanimais also perform the function.
The question is how to do what #Dating and #Quantidadeanimais no 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;
})
)}
Can do $('#field, #field2') or with classnames , $('.field'), the classname can be identified in more than one element.
– AnthraxisBR