Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
update record on submit (CRUD, DOM manipulation)

A complete beginner here. I am trying to update the innerText of the a label when an user clicks on the "update" button.

this is what I have in my ejs file:

<div>
      <ul>
        <% habits.forEach(item=> { %>
          <li>
            <label id=<%=item.id %> class="<%= item.title %>" for="<%= item.title %>">
              <%= item.title %>
            </label>
                <button><span id="<%=item.id%>" class="habit"> delete</span></button>
                <button class="editBtn" id=<%=item.id %>>Edit</button>
          </li>
          <% }) %>
          </ul>
              <form class="mainForm" id="habitForm" action="/manageHabits" method="GET">
                <label for="editButton"></label>
                <input type="hidden" name="habitId" />
                <input id="updateInput" type="text" name="habitName" />
                <input type="submit" id="submit" value="Update" />
              </form>
    </div>

and this is what I have in my js:

    let form = document.querySelector("#habitForm")
    form.addEventListener("submit", async (e) => {
        e.preventDefault();
        let updateInput = document.querySelector("#updateInput");
        let value = updateInput.value;
        let label = document.querySelectorAll("label");
        
        label.innerText = value;
        let primaryKey = label.id;
        let url = `/manageHabits/${primaryKey}`;
        console.log(value)
        // label = document.querySelector('label')
        
        // console.log(e)
        // let parentEl = e.target.parentElement;
        // parentEl.querySelector("label").innerText = updateForm["habitName"].value;
        //updateForm["habitId"].value = parentEl.id;
        let results = await fetch(url, {
        method: "PUT",
        headers: { 'Content-type': 'application/json; charset=UTF-8' },
    });
    let records = await results.json();
    refresh(records);
    });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda