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

212
Views
how can I submit my form and after submit i want to update doc to firestore database

I have tried the following but it only works either in submitting the form or updating to the Firestore database.

I want to submit my form first then after the form is submitted I want to update a doc in Firestore.

 <form action='/search' method="post">
                                    
    <input type="text"  value="{{ query }}"/>
    <input type="submit" value="submit"/>

</form>

and my javascript code

 <script>
function update()
{
    
    db = firebase.firestore()
    db.collection("users").doc(userid).update({
    "number": 2,

})
.then(() => {
    console.log("Document successfully written!");
    })
.catch((error) => {
    console.error("Error writing document: ", error);
    
    });
}
</script>


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

0

Intercept the form submit and then programmatically submit the form via an asynchronous request (so that your current page is not reloaded). After this, call the code to update your db.

Refer to this article for sample code on how to intercept your form submit and then do an asynchronous request. Your call to update your db will go into the bit that says .done(function (data) {

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!