Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Lets start with GitHub !!


test change
62 changes: 62 additions & 0 deletions RoeiBi/form/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en-US">

<head>
<meta charset="utf-8">
<link rel="stylesheet" href="styles/styles.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Student details</title>
</head>

<body>
<div class="container">
<div class="formDIV">
<p>Please fill-in student detials</p>
<form>
<ul>
<li>
<label for="fname">First name:</label>
<input type="text" id="fname" name="first_name">
</li>
<li>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="last_name">
</li>
<li>
<label for="email">E-mail:</label>
<input type="email" id="email" name="student_email">
</li>
<li>
<label for="sstatus">Status:</label>
<select name="sstatus" id="sstatus">
<option value="married">Married</option>
<option value="bachelor">Bachelor</option>
</select>
</li>
<li class="button">
<button type="button" onclick="saveBtn()">Save</button>
</li>
<li>
<button onclick="clearStudents()">Clear LS</button>
</li>
</ul>
</form>
</div>
<div class="studentsTable">
<table id="sTable" class="table">
<thead class="thead-dark">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Status</th>
</tr>
</thead>
</table>
</div>
</div>
<script type="text/javascript" src="js/script.js"></script>
</body>

</html>
85 changes: 85 additions & 0 deletions RoeiBi/form/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
let studentsStr = []
window.onload = checkLocalStorage()

class saveStudent {
constructor(fname, lname, email, sstatus) {
this.fname = fname,
this.lname = lname,
this.email = email,
this.sstatus = sstatus
}
}

function checkLocalStorage() {
if (window.localStorage.getItem("student")) {
studentsStr = JSON.parse(localStorage.getItem("student"));
console.log(studentsStr)
for (i = 0; i < studentsStr.length; i++) {
loopStudent = studentsStr[i]
addToTable(loopStudent.fname, loopStudent.lname, loopStudent.email, loopStudent.sstatus)
}
}
else {
console.log("no students on local storage yet")
}
}

function saveBtn() {
fname = document.getElementById("fname").value;
lname = document.getElementById("lname").value;
email = document.getElementById("email").value;
sstatus = document.getElementById("sstatus").value;
if (window.localStorage.getItem("student")) {
studentsStr = JSON.parse(localStorage.getItem("student"));
for (i = 0; i < studentsStr.length; i++) {
if (studentsStr[i].fname == fname){
console.log("name already exists")
return;
}
else continue;
}
}
let student = new saveStudent(fname, lname, email, sstatus);
studentsStr.push(student);
window.localStorage.setItem("student", JSON.stringify(studentsStr));
// console.log("student saved in local storage: " + window.localStorage.getItem("student"));
addToTable(fname, lname, email, sstatus)
}

function addToTable(fname, lname, email, sstatus) {
let table = document.getElementById("sTable");
let newRow = table.insertRow();
newRow.insertCell().innerHTML = fname
newRow.insertCell().innerHTML = lname
newRow.insertCell().innerHTML = email
newRow.insertCell().innerHTML = sstatus
}

// No need for this function
// function getStudents() {
// if (window.localStorage.getItem("student")) {
// let studentsStr = JSON.parse(window.localStorage.getItem("student"));
// console.log(studentsStr);
// for (let i = 0; i < studentsStr.length; i++) {
// console.log(studentsStr[i].index)
// //innerHTML here
// }
// }
// else console.log("no students registered");
// }

function clearStudents() {
if (!window.localStorage.getItem("student")) {
console.log("ls is empty");
}
else {
let table = document.getElementById("sTable");
let rowCount = table.rows.length
console.log(rowCount)
for (let i = rowCount; i > 1; i--) {
table.deleteRow(i - 1);
console.log("row: ", i);
}
window.localStorage.removeItem("student")
}
}
18 changes: 18 additions & 0 deletions RoeiBi/form/styles/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.container {
margin: 0 auto;
width: 800px;
}
label {
width: 80px;
display: inline-block;
}
input {
padding: 2px;
}
textarea {
max-width: 170px;
max-height:160px;
}
ul li {
margin-top: 10px;
}