HTML Indexeddb Insert

You are Here:

HTML Indexeddb Insert

In the following example, we will create a table ('MyTableName') under the database ('MyDatabase') and insert some data.


HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB; var open ="MyDatabase", 1); // Create a table open.onupgradeneeded = function(){ var db = open.result; var store = db.createObjectStore("MyTableName", {keyPath: "id"}); var index = store.createIndex("NameIndex", ["name.last", "name.first"]); }; open.onsuccess = function(){ // Start a new transaction var db = open.result; var tx = db.transaction("MyTableName", "readwrite"); var store = tx.objectStore("MyTableName"); var index = store.index("NameIndex"); // Add some data store.put({id: 0001, name: {first: "Brenden", last: "Eich"}, age: 58}); store.put({id: 0002, name: {first: "Dennis", last: "Ritchie"}, age: 70}); x.innerHTML = "Data Added Successfully"; // Close the db when the transaction is done tx.oncomplete = function(){ db.close(); }; } </script> </body> </html>


Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in HTML.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author