Well, it really depends on where the database is. If it's a client side database I would recommend using the
Indexed DB[
^] approach. If it's a server side database, then I would recommend using AJAX to transmit a request to a server side method (I like RESTful services for this) and let the server side code manage the insert. For this approach, search on AJAX REST JavaScript and insert the database of your choice in here as your search terms.