• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

JavaScript - Simple To Do List App

Protox39

IoT Systems Integrator
P Rep
0
0
0
Rep
0
P Vouches
0
0
0
Vouches
0
Posts
94
Likes
60
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
In this tutorial we will create a Simple To Do List App using JavaScript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It can renders web pages in an interactive and dynamic fashion. It is widely used in designing a stunning website. This code can be used as your converter to your mathematical problem. So Let's do the coding...

Getting started:

This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.

  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. </

    head

    >
  7. <body

    >
  8. <nav class

    =

    "navbar navbar-default"

    >
  9. <div

    class

    =

    "container-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  11. </

    div

    >
  12. </

    nav>
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    Javascript - Simple To Do List App</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  17. <div

    class

    =

    "form-inline"

    >
  18. <label

    >

    Add Item</

    label

    >
  19. <input

    type

    =

    "text"

    id

    =

    "item"

    class

    =

    "form-inline"

    /

    >
  20. <button

    class

    =

    "btn btn-success"

    onclick

    =

    "addItem()"

    ><span

    class

    =

    "glyphicon glyphicon-plus"

    ></

    span

    ></

    button

    >
  21. </

    div

    >
  22. <center

    ><h3

    class

    =

    "text-primary"

    >

    My To Do List</

    h3

    ></

    center

    >
  23. <ul

    class

    =

    "list-group"

    id

    =

    "list"

    style

    =

    "word-wrap:break-word;"

    /

    >
  24. </

    ul

    >
  25. </

    div

    >
  26. </

    body

    >
  27. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  28. </

    html

    >

Creating the Script

This code contains the script of the application. This code can add your task by adding in the data input to view the list of all your workloads. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder.
  1. var

    items =

    document.getElementById

    (

    'list'

    )

    ;
  2. var

    list =

    [

    ]


  3. function

    displayList(

    )

    {
  4. var

    data =

    ''

    ;
  5. if

    (

    list.length

    >

    0

    )

    {
  6. for

    (

    var

    i=

    0

    ;

    i <

    list.length

    ;

    i++

    )

    {
  7. data +=

    "<li class='list-group-item'><button class='pull-right' onclick='removeItem("

    +

    i+

    ")'><span class='glyphicon glyphicon-trash text-danger'></span></button>"

    +

    list[

    i]

    +

    "</li>"

    ;
  8. }
  9. }

  10. document.getElementById

    (

    'list'

    )

    .innerHTML

    =

    data;
  11. }

  12. function

    addItem(

    )

    {
  13. var

    item =

    document.getElementById

    (

    'item'

    )

    ;
  14. var

    val =

    item.value

    ;
  15. if

    (

    val ==

    ""

    )

    {
  16. alert(

    "Please enter something first!"

    )

    ;
  17. }

    else

    {
  18. list.push

    (

    val.trim

    (

    )

    )

    ;
  19. item.value

    =

    ''

    ;
  20. displayList(

    )

    ;
  21. }

  22. }


  23. function

    removeItem(

    item)

    {
  24. list.splice

    (

    item,

    1

    )

    ;
  25. displayList(

    )

    ;
  26. }

⚙ Live Demo

There you have it we successfully created a Simple To Do List App using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,502

355,786

355,794

Top