123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <html>
- <head><title> Read, write, Update, Deleta Data Firebase JS</title></head>
-
- <body>
- productId <input id="idbox" type="text"></input><br><br>
- attribute <input id="attributebox" type="text"></input><br><br>
- category <input id="categorybox" type="text"></input><br><br>
- imageUrl <input id="imageUrlbox" type="text"></input><br><br>
- marketPrice <input id="marketPricebox" type="text"></input><br><br>
- name <input id="namebox" type="text"></input><br><br>
- ourPrice <input id="ourPricebox" type="text"></input><br><br>
- units <input id="unitsbox" type="text"></input><br><br>
- <br><br>
- <button id = "insert">INSERT</button>
- <button id = "select">SELECT</button>
- <button id = "update">UPDATE</button>
- <button id = "delete">DELETE</button>
-
- <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js"></script>
- <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-auth.js"></script>
- <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-database.js"></script>
- <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-analytics.js"></script>
-
- <script id="MainScript">
- var firebaseConfig = {
- apiKey: "AIzaSyAilkN9V1yNMfqCvPGTeiovVLOBSx1w1cc",
- authDomain: "comedoresescolares-82ede.firebaseapp.com",
- databaseURL: "https://comedoresescolares-82ede-default-rtdb.firebaseio.com",
- projectId: "comedoresescolares-82ede",
- storageBucket: "comedoresescolares-82ede.appspot.com",
- messagingSenderId: "182848144209",
- appId: "1:182848144209:web:27dfc87c0c49d2f9534970",
- measurementId: "G-4KK5ME3PJ5"
- };
- // Initialize Firebase
- firebase.initializeApp(firebaseConfig);
- firebase.analytics();
-
- //var productV
- var attributeV, categoryV, imageUrlV, marketPriceV, nameV, ourPriceV, unitsV;
-
- function Ready(){
- productV = document.getElementById('idbox').value;
- attributeV = document.getElementById('attributebox').value;
- categoryV = document.getElementById('categorybox').value;
- imageUrlV = document.getElementById('imageUrlbox').value;
- marketPriceV = document.getElementById('marketPricebox').value;
- nameV = document.getElementById('namebox').value;
- ourPriceV = document.getElementById('ourPricebox').value;
- unitsV = document.getElementById('unitsbox').value;
- }
-
- document.getElementById('insert').onclick = function(){
- Ready();
- firebase.database().ref('products/'+ Math.random().toString(36).substring(2,9)).set ({
- //productId: productV,
- attribute: attributeV,
- categoryId: categoryV,
- imageUrl: imageUrlV,
- marketPrice: marketPriceV,
- name: nameV,
- ourPrice: ourPriceV,
- units: unitsV
- })
- }
-
- document.getElementById('delete').onclick = function(){
- Ready();
- firebase.database().ref('Product/'+ productV).remove();
- }
-
- </script>
-
- </body>
- </html>
|