im creating a html form that stores data in a firebase database and when i try to run the code it give this error Uncaught ReferenceError: firebase is not defined. i tried to do as the other posts but did not work
im creating a html form that stores data in a firebase database and when i try to run the code it give this error Uncaught ReferenceError: firebase is not defined. i tried to do as the other posts but did not work
“’
// Import the functions you need from the SDKs you need
import { initializeApp } from “https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js”;
import “https://www.gstatic.com/firebasejs/10.11.1/firebase-database.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: "ddd",
authDomain: "ddd",
databaseURL: "ddd",
projectId: "dd",
storageBucket: "dd",
messagingSenderId: "dd",
appId: "1:ddd"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Reference to your 'orderform' node in the database
const database = firebase.database();
const orderformDB = database.ref('orderform');
// Event listener for form submission
document.getElementById("orderForm").addEventListener("submit", submit1);
function submit1(e){
e.preventDefault(); // Prevent default form submission
// Get form values
const name = document.getElementById('name').value;
const item = document.getElementById('item').value;
const pickupDate = document.getElementById('pickupDate').value;
console.log(name, item, pickupDate);
// Push the order data to the database
const newOrderRef = orderformDB.push(); // Push to 'orderform' node
newOrderRef.set({
name: name,
item: item,
pickupDate: pickupDate
});
// Clear form fields
document.getElementById('name').value = '';
document.getElementById('item').value = '';
document.getElementById('pickupDate').value = '';
// Show success message
alert('Your order has been submitted successfully!');
};
</script>
“`
Dilipan Andhivarman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.