I have tried to make it so that when the addLate function is called, the lates column in the student table increments by one. However, the lates column in the student table does not seem to update.
HTML:
<fieldset>
<legend><h2>Details</h2></legend>
<label>First Name: </label><input type = "text" id="firstname" style = "background-color: lightgrey" readonly><br><br>
<label>First Name: </label><input type = "text" id="lastname" style = "background-color: lightgrey" readonly><br><br>
</fieldset>
<fieldset>
<legend><h2>Information</h2></legend>
<label> Current date:</label>
<input type="text" id="datelate" style = "background-color: lightgrey" readonly><br><br>
<label> Detention date:</label>
<input id = "detentiondate" type="date" ><br><br>
<label>Time: </label>
<select id="mora">
<option value="AM">Morning</option>
<option value="PM">Afternoon</option>
</select>
<br> <br>
<label> Reason:</label>
<textarea id = "reason" rows="2" cols="60"></textarea><br><br>
</fieldset>
<br>
<button type="button" onclick="relocate();">Cancel</button>
<button type="button" id="addlate" onclick="addLate();">Add late</button>
Script:
if (window.openDatabase) {
var mydb = openDatabase("students2_db", "0.1", "A Database of Students", 1024 * 1024);
mydb.transaction(function (t) {
t.executeSql("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY ASC, fname TEXT, lname TEXT, mclass TEXT, aclass TEXT, com TEXT, lates INTEGER DEFAULT 0)");
t.executeSql("CREATE TABLE IF NOT EXISTS lates (lid INTEGER PRIMARY KEY ASC, flname TEXT, llname TEXT, time TEXT, reason TEXT, date TEXT, nextdet TEXT)");
});
} else {
alert("WebSQL is not supported by your browser!");
}
function relocate() {
window.location.href = "AddLatecoming.html";
}
function getname() {
mydb.transaction(function (t) {
t.executeSql("SELECT fname FROM student WHERE id = ?", [localStorage.id], updateList);
});
}
function getname2() {
mydb.transaction(function (t) {
t.executeSql("SELECT lname, lname FROM student WHERE id = ?", [localStorage.id], updateList2);
});
}
function updateList(transaction, results) {
var listitems = "";
var listholder = document.getElementById("firstname");
listholder.innerHTML = "";
var i;
for (i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
document.getElementById("firstname").value = " " + row.fname;}
document.getElementById("firstname").style.fontWeight = "900";
}
function updateList2(transaction, results) {
var listitems = "";
var listholder = document.getElementById("lastname");
listholder.innerHTML = "";
var i;
for (i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
document.getElementById("lastname").value = " " + row.lname;}
document.getElementById("lastname").style.fontWeight = "900";
localStorage.id= undefined;
}
function ClearFunction() {
document.getElementById("mora").value = "";
}
function addLate() {
if (mydb) {
var flname = document.getElementById("firstname").value;
var llname = document.getElementById("lastname").value;
var date = document.getElementById("datelate").value;
var nextdet = document.getElementById("detentiondate").value;
var time = document.getElementById("mora").value;
var reason = document.getElementById("reason").value;
if (flname !== "" && date !== "" && nextdet !== "" && llname !== "" && reason !== "" && time !== "") {
mydb.transaction(function (t) {
t.executeSql("INSERT INTO lates (flname,llname,time,reason,date,nextdet) VALUES (?,?,?,?,?,?)" , [flname,llname,time,reason,date,nextdet]);
t.executeSql("UPDATE student SET lates = lates + 1 WHERE lname =? AND fname = ?", [llname, flname]);
alert("Entry succesfully added");
window.location.href = "AddLatecoming.html";
});
} else {
alert("You must fill out all the empty information!");
}
} else {
alert("db not found, your browser does not support web sql!");
}
}
Aucun commentaire:
Enregistrer un commentaire