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!