How do I force onChange when the page loads?

Asked

Viewed 39 times

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()"> ?

  • I tried, but it didn’t work either.

  • You have the option to run by JS: <script>document.getElementById("myFrame").onload = function() {myFunction()};</script>

  • OK, I’ll try

  • I didn’t understand if I could be clearer?

  • 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

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.