Files
Web-Dev-Classwork-2022/Unit 5/Day 2/js/submission.js
Benjamin Adovasio ca92b603be added other units
2025-11-16 22:54:34 -05:00

54 lines
2.9 KiB
JavaScript

submissionCounter = 0;
if (localStorage.length % 4 === 0) {
if(localStorage.length >0 ){
submissionCounter = localStorage.length / 4 ;
console.log(submissionCounter);
for(i = 1; i < submissionCounter + 1; i++ ){
var tbodyRef = document.getElementById('todoTable').getElementsByTagName('tbody')[0];
var newRow = tbodyRef.insertRow();
var newCell = newRow.insertCell();
var newCell2 = newRow.insertCell();
var newCell3 = newRow.insertCell();
var newCell4 = newRow.insertCell();
var newText = document.createTextNode("Item ID: " + localStorage.getItem("ID: " + i + " - Item ID:"));
newCell.appendChild(newText);
var newText2 = document.createTextNode("Name: " + localStorage.getItem("ID: " + i + " - Name:"));
newCell2.appendChild(newText2);
var newText3 = document.createTextNode("Task: " + localStorage.getItem("ID: " + i + " - Task:"));
newCell3.appendChild(newText3);
var newText4 = document.createTextNode("Priorty: " + localStorage.getItem("ID: " + i + " - Priority:"));
newCell4.appendChild(newText4);
}
}
}
function submission(){
document.getElementById('content').value="";
document.getElementById('content').placeholder="e.g. Clean Room";
for(var i=0;i<document.getElementsByName("category").length;i++){
document.getElementsByName("category")[i].checked = false;
}
submissionCounter ++;
localStorage.setItem("ID: " + submissionCounter + " - Item ID:", submissionCounter);
localStorage.setItem("ID: " + submissionCounter + " - Name:", document.getElementById('name').value);
localStorage.setItem("ID: " + submissionCounter + " - Task:", document.getElementById('content').value);
if(document.getElementById('category1').checked){
localStorage.setItem("ID: " + submissionCounter + " - Priority:", "High");
}
else {
localStorage.setItem("ID: " + submissionCounter + " - Priority:", "Low");
}
var tbodyRef = document.getElementById('todoTable').getElementsByTagName('tbody')[0];
var newRow = tbodyRef.insertRow();
var newCell = newRow.insertCell();
var newCell2 = newRow.insertCell();
var newCell3 = newRow.insertCell();
var newCell4 = newRow.insertCell();
var newText = document.createTextNode("Item ID: " + localStorage.getItem("ID: " + submissionCounter + " - Item ID:"));
newCell.appendChild(newText);
var newText2 = document.createTextNode("Name: " + localStorage.getItem("ID: " + submissionCounter + " - Name:"));
newCell2.appendChild(newText2);
var newText3 = document.createTextNode("Task: " + localStorage.getItem("ID: " + submissionCounter + " - Task:"));
newCell3.appendChild(newText3);
var newText4 = document.createTextNode("Priorty: " + localStorage.getItem("ID: " + submissionCounter + " - Priority:"));
newCell4.appendChild(newText4);
}