{"id":3415,"date":"2012-06-03T06:15:33","date_gmt":"2012-06-03T06:15:33","guid":{"rendered":"http:\/\/2slick.com\/web\/?p=3415"},"modified":"2012-06-03T06:15:33","modified_gmt":"2012-06-03T06:15:33","slug":"word-counter-javascript","status":"publish","type":"post","link":"https:\/\/2slick.com\/web\/word-counter-javascript\/affordablewebsitestips\/tutorials","title":{"rendered":"Word Counter JavaScript"},"content":{"rendered":"<p>Here is a free word counter tool using JavaScript. Feel free to copy the code snippet below and use it on your own web page. Here is the <a title=\"Word Counter Tool\" href=\"http:\/\/2slick.com\/web\/word-counter-tool\" target=\"_blank\">word counter tool<\/a> in action.<\/p>\n<h3>Word Counter JavaScript code<\/h3>\n<p>Place this block of code in the head section of your HTML document:<br \/>\n<!--DEVFMTCODE--><pre class=\"devcodeblock\" title=\"Javascript\"><table class=\"devcodetools\"><tbody><tr><td>&nbsp;Javascript&nbsp;|&nbsp;<\/td><td style=\"background-image:url('https:\/\/2slick.com\/web\/wp-content\/plugins\/devformatter\/img\/devformatter-copy.png');background-repeat:no-repeat;background-position:50% 50%;width:16px;height:16px;\"\/><embed id=\"ZeroClipboard1\" src=\"https:\/\/2slick.com\/web\/wp-content\/plugins\/devformatter\/_zclipboard.swf\" loop=\"false\" menu=\"false\" quality=\"best\" bgcolor=\"#ffffff\" width=\"16px\" height=\"16px\" align=\"middle\" allowScriptAccess=\"always\" allowFullScreen=\"false\" type=\"application\/x-shockwave-flash\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" flashvars=\"id=1&width=16&height=16\" wmode=\"transparent\" \/><\/td><td>&nbsp;copy&nbsp;code&nbsp;|<\/td><td style=\"cursor:pointer\" title=\"DevFormatter Plugin\" onclick=\"devfmt_credits()\">?<\/td><td width=\"99%\">&nbsp;<\/td><\/tr><\/tbody><\/table><div class=\"devcodeoverflow\"><table class=\"devcodearea\" width=\"100%\"><tr><td class=\"devcodelines\" width=\"1%\">1<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">2<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"><span style=\"color: #339933;\">&lt;<\/span>script language<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;javascript&quot;<\/span><span style=\"color: #339933;\">&gt;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">3<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><span style=\"color: #003366; font-weight: bold;\">function<\/span> countWords<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">4<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\">\tdocument.<span style=\"color: #660066;\">form1<\/span>.<span style=\"color: #660066;\">wordcount<\/span>.<span style=\"color: #660066;\">value<\/span> <span style=\"color: #339933;\">=<\/span> document.<span style=\"color: #660066;\">form1<\/span>.<span style=\"color: #660066;\">inputString<\/span>.<span style=\"color: #660066;\">value<\/span>.<span style=\"color: #660066;\">split<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #3366CC;\">' '<\/span><span style=\"color: #009900;\">&#41;<\/span>.<span style=\"color: #660066;\">length<\/span><span style=\"color: #339933;\">;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">5<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">6<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"><span style=\"color: #339933;\">&lt;\/<\/span>script<span style=\"color: #339933;\">&gt;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">7<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><\/pre><\/td><\/tr><\/table><\/div><\/pre><!--END_DEVFMTCODE--><\/p>\n<p>Place this block in the body section of your HTML Document:<br \/>\n<!--DEVFMTCODE--><pre class=\"devcodeblock\" title=\"Javascript\"><table class=\"devcodetools\"><tbody><tr><td>&nbsp;Javascript&nbsp;|&nbsp;<\/td><td style=\"background-image:url('https:\/\/2slick.com\/web\/wp-content\/plugins\/devformatter\/img\/devformatter-copy.png');background-repeat:no-repeat;background-position:50% 50%;width:16px;height:16px;\"\/><embed id=\"ZeroClipboard2\" src=\"https:\/\/2slick.com\/web\/wp-content\/plugins\/devformatter\/_zclipboard.swf\" loop=\"false\" menu=\"false\" quality=\"best\" bgcolor=\"#ffffff\" width=\"16px\" height=\"16px\" align=\"middle\" allowScriptAccess=\"always\" allowFullScreen=\"false\" type=\"application\/x-shockwave-flash\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" flashvars=\"id=2&width=16&height=16\" wmode=\"transparent\" \/><\/td><td>&nbsp;copy&nbsp;code&nbsp;|<\/td><td style=\"cursor:pointer\" title=\"DevFormatter Plugin\" onclick=\"devfmt_credits()\">?<\/td><td width=\"99%\">&nbsp;<\/td><\/tr><\/tbody><\/table><div class=\"devcodeoverflow\"><table class=\"devcodearea\" width=\"100%\"><tr><td class=\"devcodelines\" width=\"1%\">1<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">2<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"><span style=\"color: #339933;\">&lt;<\/span>form <span style=\"color: #000066;\">name<\/span><span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;form1&quot;<\/span> method<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;post&quot;<\/span><span style=\"color: #339933;\">&gt;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">3<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><span style=\"color: #339933;\">&lt;<\/span>textarea <span style=\"color: #000066;\">name<\/span><span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;inputString&quot;<\/span> cols<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;65&quot;<\/span> rows<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;20&quot;<\/span><span style=\"color: #339933;\">&gt;&lt;\/<\/span>textarea<span style=\"color: #339933;\">&gt;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">4<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"><span style=\"color: #339933;\">&lt;<\/span>br<span style=\"color: #339933;\">&gt;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">5<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><span style=\"color: #339933;\">&lt;<\/span>input type<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;button&quot;<\/span> <span style=\"color: #000066;\">name<\/span><span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;Convert&quot;<\/span> value<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;Count Words&quot;<\/span> onClick<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;countWords();&quot;<\/span><span style=\"color: #339933;\">&gt;<\/span> <\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">6<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"><span style=\"color: #339933;\">&lt;<\/span>input <span style=\"color: #000066;\">name<\/span><span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;wordcount&quot;<\/span> type<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;text&quot;<\/span> value<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;&quot;<\/span> size<span style=\"color: #339933;\">=<\/span><span style=\"color: #3366CC;\">&quot;6&quot;<\/span><span style=\"color: #339933;\">&gt;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">7<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><span style=\"color: #339933;\">&lt;\/<\/span>form<span style=\"color: #339933;\">&gt;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">8<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"><\/pre><\/td><\/tr><\/table><\/div><\/pre><!--END_DEVFMTCODE--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a free word counter tool using JavaScript. Feel free to copy the code snippet below and use it on your own web page. Here is the word counter tool in action. Word Counter JavaScript code Place this block of code in the head section of your HTML document: &nbsp;Javascript&nbsp;|&nbsp;&nbsp;copy&nbsp;code&nbsp;|?&nbsp;12&lt;script language=&quot;javascript&quot;&gt;3function countWords&#40;&#41;&#123;4 document.form1.wordcount.value = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3416,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,4],"tags":[385],"class_list":["post-3415","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-affordablewebsitestips","category-tutorials","tag-javascript"],"_links":{"self":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/3415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/comments?post=3415"}],"version-history":[{"count":1,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/3415\/revisions"}],"predecessor-version":[{"id":3417,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/3415\/revisions\/3417"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/media\/3416"}],"wp:attachment":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/media?parent=3415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/categories?post=3415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/tags?post=3415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}