Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
actualizar el registro al enviar (CRUD, manipulación DOM)

Un completo principiante aquí. Estoy tratando de actualizar el texto interno de una etiqueta cuando un usuario hace clic en el botón "actualizar".

esto es lo que tengo en mi archivo ejs:

 <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>

y esto es lo que tengo en mi 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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!