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

344
Views
¿La entrada de texto se guarda al hacer clic en el campo no en el botón a continuación?

Tengo un código que guarda texto en Firestore y funciona, pero solo funciona cuando haces clic en el campo de texto después de escribir.

Esto guarda en Firestore. Cambié el texto entre ("...") después de getElementById a la identificación del botón, pero eso no guarda nada. Pero si lo tengo como la identificación del campo de texto, el texto se guarda al hacer clic en el campo de texto después de escribir.

 document.getElementById("hrtitle").addEventListener("click", function saveHeroTitle() { const title = document.getElementById('hrtitle').value; console.log(title); const heroTitleRef = doc(db, "pages", "homePage"); // something around line 42 vv setDoc(heroTitleRef, { heroText: title, }, {merge: true}).then(function() { console.log("Hero Title Saved"); }).catch(function(error){ console.log("Error: ", error); }); });

Código para el campo de texto y el botón.

 <label for="uetitle">Update Hero Title</label> <input type="text" id="hrtitle" name="hrtitle"> <button class="save-button" id="hrtitleSave" type="submit">Save</button>

¿Cómo hago para que el texto se guarde al hacer clic en el botón?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que está usando la identificación incorrecta para obtener su botón. Este código debería estar funcionando:

 document.getElementById("hrtitleSave").addEventListener("click", function saveHeroTitle() { const title = document.getElementById('hrtitle').value; console.log(title); const heroTitleRef = doc(db, "pages", "homePage"); // something around line 42 vv setDoc(heroTitleRef, { heroText: title, }, {merge: true}).then(function() { console.log("Hero Title Saved"); }).catch(function(error){ console.log("Error: ", error); }); });

__

 <label for="uetitle">Update Hero Title</label> <input type="text" id="hrtitle" name="hrtitle"> <button class="save-button" id="hrtitleSave" type="submit">Save</button>
about 4 years ago · Juan Pablo Isaza Report
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!