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

192
Views
How to upload data to firebase by clicking button in form tag

Hi I was struggling for this issue for hours, and need any experts to help!

I'm trying to upload my data to Firebase database by clicking button in form, but it's not working... I think the problem occurs when I click the button in the form tag. Should I use addEventListener'click' instead of 'submit'?

Please refer to the codes below. Truly appreciated!

HTML

   <div class="container">
    <div class="row">
      <form id="question-form" class="padT100">
        <div class="col-md-5 col-sm-6 col-xs-12">
          <div class="post-gray">
            <input
              id="name"
              type="text"
              name="full name"
              value=""
              placeholder="성함"
            />
            <input
              id="contact"
              type="text"
              name="contact"
              value=""
              placeholder="연락처"
            />
            <input
              id="store"
              type="text"
              name="store"
              value=""
              placeholder="지점명"
            />
          </div>
        </div>
        <div class="col-md-7 col-sm-6 col-xs-12">
          <div class="post-gray marT20">
            <textarea
              id="question-detail"
              placeholder="문의 내용"
              rows="5"
              cols="50"
            ></textarea>
          </div>
        </div>
        <div class="col-md-12 col-sm-6 col-xs-12 marT30">
          <button type="submit" class="itg-button-3" id="send-question">전송</button>
        </div>
      </form>
    </div>
  </div>

Javscript

<script>
  const db = firebase.firestore();
  const form = document.getElementById('question-form')
  form.addEventListener('submit', (e) => {
    const singleQuestion= {
      성함: $('#name').val(),
      연락처: $('#contact').val(),
      지점명: $('#store').val(),
      문의내용: $('#question-detail').val(),
      날짜: new Date()}

    e.preventDefault();
    db.collection('questions').add(singleQuestion)
  });
</script>

Thanks in advance!

about 4 years ago · Santiago Gelvez
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!