Open In App

JavaScript Project on Todo List

Last Updated : 22 Dec, 2023
Like Article

Todo Lists are the lists that we generally use to maintain our day-to-day tasks or list of everything that we have to do, with the most important tasks at the top of the list, and the least important tasks at the bottom. In this article, we are going to learn how to JavaScript Project on Todo List.

Preview Image:




  • Use HTML to give structure to your project.
  • Use CSS for Styling purposes
  • JavaScript will be used to provide the required functionality
    • Sets up event listeners for form submission and item clicks.
    • Handles adding and editing items in the list.
    • Displays success messages for add and edit operations.
    • Handles item deletion with a confirmation dialog.
    • Enables button based on provided reference and button ID.
    • Interactive list for adding, editing, and deleting items.

Example: This example shows an implementation of the above-explained approach.


// app.js
window.onload = () => {
    const form1 = document.querySelector("#addForm");
    let items = document.getElementById("items");
    let submit = document.getElementById("submit");
    let editItem = null;
    form1.addEventListener("submit", addItem);
    items.addEventListener("click", removeItem);
function addItem(e) {
    if (submit.value != "Submit") {
            = document.getElementById("item").value;
        submit.value = "Submit";
        document.getElementById("item").value = "";
            = "Text edited successfully";
                        .style.display = "block";
        setTimeout(function() {
                            .style.display = "none";
        }, 3000);
        return false;
    let newItem = document.getElementById("item").value;
    if (newItem.trim() == "" || newItem.trim() == null)
        return false;
        document.getElementById("item").value = "";
    let li = document.createElement("li");
    li.className = "list-group-item";
    let deleteButton = document.createElement("button");
    deleteButton.className =
        "btn-danger btn btn-sm float-right delete";
    let editButton = document.createElement("button");
    editButton.className =
            "btn-success btn btn-sm float-right edit";
function removeItem(e) {
    if ("delete")) {
        if (confirm("Are you Sure?")) {
            let li =;
                = "Text deleted successfully";
                        .style.display = "block";
            setTimeout(function() {
                        .style.display = "none";
            }, 3000);
    if ("edit")) {
        document.getElementById("item").value =
        submit.value = "EDIT";
        editItem = e;
function toggleButton(ref, btnID) {
    document.getElementById(btnID).disabled = false;


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href=
    <script src="app.js"></script>
    <title>To Do List</title>
    <header class="bg-success text-white p-5">
        <div class="container">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12">
                    <font face="Comic sans MS"
                        size="11" color="black">
                        <strong>ToDo List</strong>
    <div class="container mt-3">
        <h2>Add Items</h2>
        <label id="lblsuccess" class="text-success"
                style="display: none;">
        <form id="addForm">
            <div class="row">
                <div class="col-lg-7 col-md-7 col-sm-7">
                    <input type="text" onkeyup=
                        "toggleButton(this, 'submit')"
                        class="form-control" id="item">
                <div class="col-lg-5 col-md-5 col-sm-5">
                <input type="submit" class="btn btn-dark"
                        id="submit" value="Submit" disabled>
        <h3 class="mt-4">Tasks</h3>
        <form id="addForm">
            <ul class="list-group" id="items"></ul>

Output: Click here to see live code output

JavaScript Project on Todo List

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads