detox1978
asked on
HTML5: Add redord to indexeddb
Hi All,
I have the following code snippet that creates an IndexedDB and adds three records.
This woirks well. However I want to create another HTML page that adds to the existing records?
Any suggestions?
I have the following code snippet that creates an IndexedDB and adds three records.
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
var request = indexedDB.open("library");
request.onupgradeneeded = function() {
// The database did not previously exist, so create object stores and indexes.
var db = request.result;
var store = db.createObjectStore("books", {keyPath: "isbn"});
var titleIndex = store.createIndex("by_title", "title", {unique: true});
var authorIndex = store.createIndex("by_author", "author");
// Populate with initial data.
store.put({title: "Quarry Memories", author: "Fred", isbn: 123456});
store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567});
store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678});
};
request.onsuccess = function() {
db = request.result;
};
// <delete database>
// window.indexedDB.deleteDatabase('library');
// </delete database>
</script>
This woirks well. However I want to create another HTML page that adds to the existing records?
Any suggestions?
ASKER
Sorry I'm new to this. Where do I add the the record data?
// Populate with initial data.
store.put({title: "Quarry Memories", author: "Fred", isbn: 123456});
store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567});
store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
just create the db and then insert data with something like:
Open in new window