"Simple message book" with HTML New database implementation
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 ();
}
Web message book with database implementation
Name:
Message:
________________________________________
"Simple message book" with HTML New database implementation