0
I need to force onChange when the page loads, but I’m not getting it, I tried jQuery and it didn’t work.
Code of the onChange:
let gruArrObj = [];
let handleChangeSelectGrupoEDT = (value) => {
setGrupoUid(value);
gruArrObj.push({
grupo_uuid: value,
});
//console.log(gruArrObj);
const abc = grupos.filter(function (o1) {
return gruArrObj.some(function (o2) {
return o1.grupo_uuid === o2.grupo_uuid;
});
});
//console.log(abc);
// console.log(abc[0].gru_hab_tamanho);
try {
if (abc[0].gru_hab_tamanho === "S") {
document.getElementById("adicionarTam").style.display = "block";
} else {
document.getElementById("adicionarTam").style.display = "none";
}
} catch (e) {
document.getElementById("adicionarTam").style.display = "none";
}
};
code to call onChange:
<select
value={grupoUid}
onChange={(e) => handleChangeSelectGrupoEDT(e.target.value)}
id="select-grupoEDT"
>
{grupos.map((grupo) => (
<option value={grupo.grupo_uuid}>{grupo.gru_descricao}</option>
))}
</select>
Anyone who can help, thank you.
the function onload doesn’t help you?
<select onload="myFunction()">
?– Jhonata De souza
I tried, but it didn’t work either.
– Desenvolvedor Bot
You have the option to run by JS:
<script>document.getElementById("myFrame").onload = function() {myFunction()};</script>
– Jhonata De souza
OK, I’ll try
– Desenvolvedor Bot
I didn’t understand if I could be clearer?
– novic
I believe calling the function on
constructor()
in the case of a class component, or at the beginning of the main function, in the case of a functional component– placementw