0
Example :
$("#segundaFeira").change(function(){
valorSegundaFeira = calcularJornadaDeTrabalho(this.value);
var x = valorFinalJornadaTrabalho();
alert(x);
});
Note that the global variable valorSegundaFeira
is defined by a function that returns a value. so far so good the problem that when I call change
is printing the alert(x)
first to enter the function calcularJornadaDeTrabalho
and define the value of valorSegundaFeira
. I don’t know why you’re not following the structured algorithm.
HTML code
<select class="form-control" th:field="*{segundaFeira}" >
option value="" selected="selected">--</option>
<option th:each="horario : ${listaHorarioTrabalhoDiario}" th:value="${horario.id}"
th:text="${horario.descricao}">horario</option>
</select>
Function calculatorJornadaDework
function calcularJornadaDeTrabalho(value){
var **= 440;
var **= 528;
var **= 480;
var **= 540;
var **= 480;
var **= 240;
var **= 360;
var valorTotal = 0;
var **= 0;
$.get(urlJornadaTrabalho, {idHorario: value}).done(function (horario) {
**= horario.**;
if (**== '**') {
valorTotal = **;
}
if (**== '**') {
valorTotal = **;
}
if (**== '**') {
valorTotal = **;
}
if (**== '**') {
valorTotal = **;
}
if (**== '**') {
valorTotal = **;
}
if (**== '**') {
valorTotal = **;
}
if (**== '**') {
valorTotal = **;
}
alert("vlrTotal " + valorTotal);
}).fail(function(xhr) {
console.log("erro ao fazer ajax na urlJornadaTrabalho");
});
return valorTotal;
}
Could you please show us the HTML as well?
– PauloHDSousa
Put to calculatDeworking() also.
– Gabriel Rodrigues
OK just a moment
– Jose Vieira Neto
I’ve already made the edits
– Jose Vieira Neto
you use some framework/library js without being jquery ?
– Gabriel Rodrigues
@Gabrielrodrigues not only jquery
– Jose Vieira Neto
@Josevieiraneto the AJAX calculatedDework is done whenever the event
change
occurs?– flpms
@flpms yes is done every time I call the change event but I realized he’s not getting into the $.Get on the first call is like if underneath the scenes he calls himself twice doing q the first time the value is 0
– Jose Vieira Neto
I’ll edit my answer with something that might help you.
– flpms
You can edit the question with the basic implementation of the value?
– flpms
@flpms this function it only makes the sums of the global variables ex : valueFeira + valueTercaFeira
– Jose Vieira Neto