This code works and shows an alert of { "plantID" : "2" }. but when I try to uncomment
const newDoc = await addDoc(userPlants, data);, it doesn't push it to Firebase.
window.onsubmit = async function addPlant(){
// Specify which HTML data to get from
var selectPlants = parseInt(document.getElementById("plantID").value);
// Get reference to the collection that we are adding Data to
const userPlants = collection(firestore, "Users/" + "s6wnGQY3pH3oBGEyNJmZ/" + "Plants");
const data = {
plantID: selectPlants
};
alert(JSON.stringify(data));
//const newDoc = await addDoc(userPlants, data);
}
However, if I changed the code to
async function addPlant(){
// Specify which HTML div to use
var selectPlants = parseInt(document.getElementById("plantID").value);
// Get reference to the collection that we are adding Data to
const userPlants = collection(firestore, "Users/" + "s6wnGQY3pH3oBGEyNJmZ/" + "Plants");
const data = {
plantID: 3
};
const newDoc = await addDoc(userPlants, data);
}
and add it to the window.onload function, it works and stores it in Firebase. I've checked that const data gives the proper value. I have also tried onclick, as well as adding the functions and function call directly in the HTML folder as well, all with no luck.