0
Good afternoon friends!
Let me explain my case better. In the code I attach, we have 6 inputs. The idea is that the block <p class="nome-plano">NEXT 60 ESPORTE</p>
cannot be displayed if the value of one of these 6 inputs is greater than 65. See the code below:
const noSport = ()=> {
let sportPlan = document.querySelectorAll('.nome-plano');
if(sportPlan = "NEXT 60 ESPORTE") {
sportPlan.style.display = "none";
}
}
document.addEventListener("DOMContentLoaded", ()=> {
let paxAge = document.querySelectorAll(".idade-viajantes");
for (i=0;i<paxAge.length;i++){
let paxAgeValue = paxAge[i].value;
let paxAgeNumber = parseInt(paxAgeValue);
if(paxAgeNumber[i]>65) {
noSport();
}
}
});
<label class="group"><span>Preencha abaixo a idade dos viajantes na data da viagem</span>
<input name="idade" maxlength="2" class="idade-viajantes only-number" type="text" value="66">
<input name="idade" maxlength="2" class="idade-viajantes only-number" type="text" value="">
<input name="idade" maxlength="2" class="idade-viajantes only-number" type="text" value="">
<input name="idade" maxlength="2" class="idade-viajantes only-number" type="text" value="">
<input name="idade" maxlength="2" class="idade-viajantes only-number" type="text" value="">
</label>
<div>
<div>
<p class="nome-plano">NEXT 15</p>
<p class="preco-plano">R$52</p>
</div>
<div>
<p class="nome-plano">NEXT 60 ESPORTE</p>
<p class="preco-plano">R$52</p>
</div>
</div>
I made a loop by going through each of the inputs and transforming its string values to integers.
My idea is that if one of the fields is an integer number greater than 65 we perform the function noSport()
which should change the style of the widget to display: none;
.
However it does not run, and the browser console is not giving me error... I also tried to run the function noSport
as anonymity even opened within the conditional deviation, but not spun as well.
What am I sinning? Should I make another loop to check the individual array values if they are greater than 65? the way I’m riding the function noSport
is wrong? Would a library like jQuery help me in this case?
If anyone can give me strength I’d appreciate it!