-3
I have the following situation: I have a form with some selects and 2 inputs. One with start date that will be filled by the user who is of type date and another with type text. As image below:
<div class="panel-body">
<div class="radio">
<label>
<input type="radio" name="optionsRadios" class="bloqueio_campo" id="optionsRadios1" value="option1" onchange="getRadioSelected1()">
5 dias
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" class="bloqueio_campo" id="optionsRadios2" value="option2" onchange="getRadioSelected2()">
10 dias
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" class="bloqueio_campo" id="optionsRadios3" value="option3" onchange="getRadioSelected3()">
15 dias
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" class="bloqueio_campo" id="optionsRadios4" value="option4" onchange="getRadioSelected4()">
20 dias
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" class="bloqueio_campo" id="optionsRadios5" value="option5" onchange="getRadioSelected5()">
30 dias
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" class="bloqueio_campo" id="optionsRadios6" value="option6" onchange="getRadioSelected6()">
5 dias com a venda de 10 dias
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" class="bloqueio_campo" id="optionsRadios7" value="option7" onchange="getRadioSelected7()">
15 dias com a venda de 10 dias
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" class="bloqueio_campo" id="optionsRadios8" value="option8" onchange="getRadioSelected8()">
20 dias com a venda de 10 dias
</label>
</div><br>
<div class="col-md-2">
<label for="dt_inicio">Data início das Férias</label>
<input type="date" class="form-control" name="dt_inicio" id="dt_inicio" onchange='pegaDtInicial()'>
</div>
<div class="col-md-2">
<label for="dt_fim">Data fim das Férias</label>
<input type="text" class="form-control" name="dt_fim" id="dt_fim" readonly>
</div>
</div>
when clicking on the start date I must check which of the radios was chosen and fill in the end date input with this value.
to acquire the value of the input I made:
Function dtFinal(date){
if(getRadioSelected1){
document.getElementById("dt_fim").value = 'Radio 1 Selecionado';
}else if(getRadioSelected2){
document.getElementById("dt_fim").value = 'Radio 2 Selecionado';
}else if(getRadioSelected3){
document.getElementById("dt_fim").value = 'Radio 3 Selecionado';
}else if(getRadioSelected4){
document.getElementById("dt_fim").value = 'Radio 4 Selecionado';
}else if(getRadioSelected5){
document.getElementById("dt_fim").value = 'Radio 5 Selecionado';
}else if(getRadioSelected5){
document.getElementById("dt_fim").value = 'Radio 6 Selecionado'o;
}else if(getRadioSelected6){
document.getElementById("dt_fim").value = 'Radio 7 Selecionado'';
}else if(getRadioSelected7){
document.getElementById("dt_fim").value = 'Radio 8 Selecionado';
}else{
console.log('Valor inválido!');
}
}
Only the problem is that for some reason when clicking on any of the radios, it only fills the input dt order with the value Radio 1 Selected. He is not getting into the other ifs. Please someone can help me?
Erika, there is no way to give an answer that solves your problem. Information is missing. Making it clear: when to do
if(getRadioSelected1)
the termgetRadioSelected1
is a function that demands a parameter. In case you are testing whether the expressiongetRadioSelected1
reference something or is null and asgetRadioSelected1
is the reference to the declared functionfunction getRadioSelected1(valor)
the same is true for all other functions.– Augusto Vasques
Why can’t you give a precise answer? Because all the functions in your code are defined by the signature
getRadioSelectedXXX(valor)
require a parametervalor
and both the functionfunction pegaDtInicial(data)
and rest of the code presented do not provide enough information to infer about the origin of the value passed to the functionsgetRadioSelectedXXX(valor)
function testedfunction pegaDtInicial(data)
.– Augusto Vasques
Switching on kids, something like this would have to be done on all your if’s
if(getRadioSelected1( ??? ))
but we have no way of knowing what goes where it is written???
.– Augusto Vasques
Another thing: within each function
getRadioSelectedXXX(valor)
the way you make your comparisons are wrong. When you doif(valor = 'option1')
you’re not comparing expressions, actually you’re assigning'option1'
tovalor
when you want to make comparisons in javascript use the comparator==
to know only if the contents are equal and the comparator===
to know if the contents and types are equal.– Augusto Vasques
Thanks Augusto, you’re right, I’m not being very clear with my goal, for that reason, I’ll rewrite it again:
– Erika
Do this because the question is gathering several meaningless answers.
– Augusto Vasques