"Simple message book" with HTML New database implementation

Source: Internet
Author: User

Web message book with database implementation

var datatable = null;

var db = OpenDatabase (' Mydata ', ' ', ' My Database ', 102400);

function init () {

DataTable = document.getElementById ("DataTable");

ShowAllData ();

}

function Removealldata () {

for (var i = datatable.childnodes.length-1;i>=0;i--) {

Datatable.removechild (Datatable.childnodes[i]);

}

var tr = document.createelement (' tr ');

var Th1 = document.createelement (' th ');

var Th2 = document.createelement (' th ');

var th3 = document.createelement (' th ');

th1.innerhtml = "name";

th2.innerhtml = "message";

th3.innerhtml = "Time";

Tr.appendchild (Th1);

Tr.appendchild (Th2);

Tr.appendchild (TH3);

Datatable.appendchild (TR);

}

function ShowData (row) {

var tr = document.createelement (' tr ');

var td1 = document.createelement (' TD ');

td1.innerhtml = Row.name;

var td2 = document.createelement (' TD ');

Td2.innerhtml= Row.message;

var td3 = document.createelement (' TD ');

var t = new Date ();

T.settime (Row.time);

td3.innerhtml = t.tolocaledatestring () + "" "+t.tolocaletimestring ();

Tr.appendchild (TD1);

Tr.appendchild (TD2);

Tr.appendchild (TD3);

Datatable.appendchild (TR);

}

function ShowAllData () {

Db.transaction (Function (TX) {

Tx.executesql (' CREATE TABLE IF not ' EXISTS msgdata (name text,message text,time INTEGER) ', []);

Tx.executesql (' SELECT * from Msgdata ', [],function (Tx,rs) {

Removealldata ();

for (var i =0; i<rs.rows.length; i + +) {

ShowData (Rs.rows.item (i));

}

});

});

}

function AddData (name,message,time) {

Db.transaction (Function (TX) {

Tx.executesql (' INSERT into Msgdata VALUES (?,?,?) ', [Name,message,time],function (Tx,rs) {

Alert ("Save data Successfully!") ");

},function (Tx,rs) {

Alert (error.source+ "::" + error.message);

});

});

}

function SaveData () {

var name = document.getElementById (' name '). Value;

var memo = document.getElementById (' Memo '). Value;

var time = new Date (). GetTime ();

alert (time);

AddData (Name,memo,time);

ShowAllData ();

}

using a database implementation Web Message Book

Name:

Message:

"Simple message book" with HTML New database implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.