I have written the following code to test writing to a Firebase Realtime Database. It wrote data to the database once, but after that will do nothing. Currently, I am just trying to save the first name that the user enters on a form after they press the submit button.
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.4.0/firebase-app.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAEGiSKDCg0nkrSxHshqxPEUWxtGI1NP7Q",
authDomain: "wrud-d63af.firebaseapp.com",
databaseURL: "https://wrud-d63af-default-rtdb.firebaseio.com",
projectId: "wrud-d63af",
storageBucket: "wrud-d63af.appspot.com",
messagingSenderId: "491961850138",
appId: "1:491961850138:web:2468aff8d84e08c40ff4a3"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
import {getDatabase, set, get, update, remove, ref, child} from "https://www.gstatic.com/firebasejs/10.4.0/firebase-database.js"
const db = getDatabase()
var fname = document.getElementById("fname")
var submitBtn = document.getElementById("submitBtn")
function save(){
set(ref(db, "/"), {
Name: fname.value
})
}
submitBtn.addEventListener('click', save)
</script>