GFXVoid Graphic Design Forum

Remove Text Formatting
Loading...

» Online Users: 23,448

0 members and 23,448 guests
No Members online

» Site Navigation

 > FAQ

» Stats

Members: 35,442
Threads: 103,075
Posts: 826,688
Top Poster: cc.RadillacVIII (7,429)
Welcome to our newest member, Lekelindids
Results 1 to 3 of 3

Thread: JS Word Counter

  1. #1

    Default JS Word Counter

    Small amount of JavaScript knowledge required

    Before I even start I want to point out I did not write this piece of javascript. I am just explaining how it works for your benefit

    Ok, well here goes nothing...

    This is the whole javascript code that counts the words for you. (HTML form is added further down)
    Code:
    <script language="JavaScript">
    function countit(){
    var formcontent=document.wordcount.wordcount2.value
    formcontent=formcontent.split(" ")
    document.wordcount.wordcount3.value=formcontent.length
    }
    </script>
    Now to break it down so you can understand

    Code:
    function countit()
    This part of the javascript is activated when the 'Count Words' button is clicked. It tell the javascript to count the words and send it to the box next to the button.

    This next piece of javascript is the part that counts the words and sends the amount back to the form.
    wordcount is the form name.
    wordcount2 is the box you enter the words you want counted in
    and wordcount3 is where the number of words is displayed.

    Code:
    var formcontent=document.wordcount.wordcount2.value
    formcontent=formcontent.split(" ")
    document.wordcount.wordcount3.value=formcontent.length
    }
    The small line of code in the middle reading:
    Code:
    formcontent=formcontent.split(" ")
    Tells the javascript to count every thing after one space.
    This means if there are 2 spaces in between words it will count the 2nd space as one word.

    Here is the whole Java and HTML code
    Code:
    <form method="POST" name="wordcount">
      <script language="JavaScript">
    function countit(){
    var formcontent=document.wordcount.wordcount2.value
    formcontent=formcontent.split(" ")
    document.wordcount.wordcount3.value=formcontent.length
    }
    </script>
          <textarea rows="6" name="wordcount2" cols="30" wrap="virtual"></textarea><br>
          <input type="button" value="Count Words" onClick="countit()">
          <input type="text" name="wordcount3" size="20" title="Your word count will be displayed here">
    </form>



    Hope I explained it OK
    All comments appreciated.

    Many Thanks
    Vauxhall
    Last edited by Vauxhall; 08-21-2008 at 07:08 AM.

  2. #2
    Join Date
    Nov 2007
    Location
    London - England
    Posts
    1,841

    Default

    Easier way - open up microsoft word paste it in, >> tools >> wordcount ?

    Sorry but i dont see why this would be helpful "/
    Visit My Deviant Art



    Tutorials
    [Stalker][Spidey][Clipping Masks]


    Quote Originally Posted by Syn
    [29-07, 08:20] You're a bit weird, aren't you Lewk? Lol
    Quote Originally Posted by Apathy
    [17-10, 19:37] 720p you can see the razor burn on the crotch

  3. #3
    Join Date
    Oct 2007
    Posts
    2,782

    Default

    Quote Originally Posted by Lewk View Post
    Easier way - open up microsoft word paste it in, >> tools >> wordcount ?

    Sorry but i dont see why this would be helpful "/
    It's not about what the code does. Its about understanding code and picking up code which could work in other situations.


Similar Threads

  1. Word Association
    By tacoX in forum The Void
    Replies: 739
    Last Post: 04-08-2007, 01:03 AM
  2. The word game!!!
    By Angell in forum The Void
    Replies: 43
    Last Post: 02-20-2006, 10:14 AM
  3. Favourite Word?
    By Dale in forum The Void
    Replies: 47
    Last Post: 01-14-2006, 02:33 AM
  4. >4 letter word here<
    By Krimsyn in forum Digital Art
    Replies: 5
    Last Post: 08-09-2005, 12:14 AM
  5. One Word Game !
    By Dale in forum The Void
    Replies: 479
    Last Post: 05-19-2005, 01:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBadvanced CMPS v4.1.1