You must implement a dynamic webpage the provides a basic task-list functionality. In particular, you page should provide a user an interface to add and remove a task as well as mark a task as completed. For this version of the assignment, the tasks will be added directly in the HTML page by manipulating the DOM. Moreover, you should maintain an array that stores task details. Each task comprise of three fields:
Requirements
Your implementation should address the following requirements:
Working code implemented in and appropriate comments provided for better understanding.
Here I am attaching code for these files:
index.html:
<!DOCTYPE html5>
<html>
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
crossorigin="anonymous">
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"></script>
<link rel = "stylesheet" href = "todo.css">
<script src = "todo.js"> </script>
<title>To do list</title>
</head>
<body>
<h1>To do List</h1>
<img src =
"https://image.flaticon.com/icons/png/512/1567/1567073.png"/>
<ul id = "task_list">
</ul>
<form id = "new-task">New Task
<input class = "task-title" id = "task-title" autocomplete="off"
autofocus placeholder="New Task" type = "text">
<label for = "task-priority">Task
Priority</label>
<select name = "task-priority" id = "task-priority">
<option value="low">low</option>
<option value="med">med</option>
<option value="high">high</option>
</select>
<label for = "task-status">Task Status</label>
<input class = "task-status" name = "task-status" type = "radio"
value = "pending"> Pending
<input class = "task-status" name = "task-status" type = "radio"
value = "completed"> Completed
<input id = "submit" type = "submit">
</form>
</body>
</html>
todo.css:
body {
text-align: center;
background-color: azure;
}
img {
height: 200px;
width: 200px;
}
li{
padding-top:2px;
border: 2px black solid;
}
todo.js:
document.addEventListener('DOMContentLoaded', function() {
var tasks = [];
document.querySelector('#new-task').onsubmit = function
(event){
event.preventDefault();
const li = document.createElement('li');
let task_text =
document.querySelector('#task-title').value;
let task_priority =
document.querySelector('#task-priority').value;
let task_status;// =
document.querySelectorAll('name[task-status]').value;
let task_status_inputs =
document.querySelectorAll('[name=task-status]');
for (let i = 0; i< task_status_inputs.length;i++){
if (task_status_inputs[i].checked){
task_status = task_status_inputs[i].value;
}
}
let new_task_html = `<div class = "new-task-html">
<span> ${task_text} </span> <span>|
${task_priority} </span> <span> | ${task_status}
</span> </div>
<button class = "mark-complete"> Mark as Complete
</button> <button class = "remove"> Remove
</button>`;
//let new_task_priority = ` <span> ${task_priority}
</span>`;
//let new_task_status = `<span> ${task_status}
</span>`;
li.innerHTML = new_task_html
//li.innerHTML = document.querySelector('#task').value;
tasks.push(task_text);
document.querySelector('#task_list').append(li);
document.querySelector('#task-title').value = '';
return false;
}
document.addEventListener('click', function(event){
element = event.target;
if (element.className === 'remove'){
element.parentElement.remove();
//tasks.remove(element);
}
if (element.className === 'mark-complete' || element.className ===
'completed'){
//document.querySelector('#task-title').strike();
element.parentElement.querySelector('.new-task-html').style.textDecoration
= "line-through";
element.task_status = "completed";
}
})
});
Sample Output Screenshots:
Get Answers For Free
Most questions answered within 1 hours.