-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from yashrajpahwa/main
Added functionality to save course code with name locally
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Add course name</title> | ||
<link | ||
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" | ||
rel="stylesheet" | ||
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" | ||
crossorigin="anonymous" | ||
/> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" | ||
crossorigin="anonymous" | ||
></script> | ||
</head> | ||
<body class="bg-dark"> | ||
<div | ||
class="d-flex flex-column justify-content-center align-items-center vh-100" | ||
> | ||
<form id="courseForm"> | ||
<div class="form-group"> | ||
<label for="courseCode text-white" | ||
><p class="text-white">Course Code:</p></label | ||
> | ||
<input | ||
type="text" | ||
class="form-control" | ||
id="courseCode" | ||
name="courseCode" | ||
required | ||
/> | ||
</div> | ||
<div class="form-group mt-2"> | ||
<label for="courseName text-white" | ||
><p class="text-white">Course Name:</p></label | ||
> | ||
<input | ||
type="text" | ||
class="form-control" | ||
id="courseName" | ||
name="courseName" | ||
required | ||
/> | ||
</div> | ||
<button type="submit" class="btn btn-primary w-100 mt-2">Save</button> | ||
</form> | ||
<a href="/" class="text-center text-white mt-4 btn btn-outline-secondary" | ||
>Go to home</a | ||
> | ||
</div> | ||
|
||
<script> | ||
document | ||
.getElementById("courseForm") | ||
.addEventListener("submit", function (event) { | ||
event.preventDefault(); | ||
var courseCode = document.getElementById("courseCode").value; | ||
var courseName = document.getElementById("courseName").value; | ||
var course = { | ||
code: courseCode.trim(), | ||
name: courseName.trim(), | ||
}; | ||
let courseLocal = localStorage.getItem("course"); | ||
courseArray = []; | ||
if (courseLocal) { | ||
courseArray = JSON.parse(courseLocal); | ||
} | ||
courseArray.push(course); | ||
localStorage.setItem("course", JSON.stringify(courseArray)); | ||
alert("Course saved successfully!"); | ||
document.getElementById("courseForm").reset(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters