• We just launched and are currently in beta. Join us as we build and grow the community.

Auto Word Counter Using JavaScript

timetogo

Knowledge Graph Expert
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
136
Likes
70
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
This code will tackle about Auto Word Counter using JavaScript. The program has a same function of a MS Word that can track every word you entered. You’re free to use this code as your reference. To learn more about this, just follow the steps below.

Getting started:

First you have to download bootstrap framework, 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"

    >

    Auto Word Counter Using JavaScript</

    h3

    >
  16. <hr

    style

    =

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

    /

    >
  17. <div

    class

    =

    "col-md-6"

    >
  18. <center

    ><button

    class

    =

    "btn btn-success"

    onclick

    =

    "reset()"

    >

    Reset</

    button

    ></

    center

    >
  19. <br

    /

    >
  20. <div

    class

    =

    "form-group"

    >
  21. <textarea

    class

    =

    "form-control"

    onkeyup

    =

    "wordCount(this.value);"

    style

    =

    "resize:none; height:150px;"

    ></

    textarea

    >
  22. </

    div

    >
  23. <center

    >
  24. <div

    id

    =

    "result"

    ></

    div

    >
  25. </

    center

    >
  26. </

    div

    >
  27. </

    div

    >
  28. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  29. </

    body

    >
  30. </

    html

    >

Creating the Script

This code contains the script of the application. The code will automatically count the words when you enter in the text field. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.
  1. function

    wordCount(

    val)

    {
  2. var

    count =

    parseInt(

    val)

    ;
  3. var

    wordCount=

    val.split

    (

    " "

    )

    ;
  4. document.getElementById

    (

    "result"

    )

    .innerHTML

    =

    "Total number of words:"

    +

    " <label class='text-primary' style='font-size:20px;'>"

    +

    wordCount.length

    +

    "</label>"

    ;
  5. }

  6. function

    reset(

    )

    {
  7. document.getElementById

    (

    "result"

    )

    .innerHTML

    =

    ""

    ;
  8. document.getElementById

    (

    "words"

    )

    .value

    =

    ""

    ;
  9. }

There you have it we successfully created a Auto Word Counter 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!

 

452,496

335,120

335,128

Top