Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • Code University
  • Word Counter
Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ;)

Interested in joining? Click here.


If you are already a member of ZBCode, feel free to login right here:

Username:   Password:
Locked Topic
Word Counter
Tweet Topic Started: Mar 29 2009, 01:14 PM (250 Views)
Vitality Mar 29 2009, 01:14 PM Post #1
Member Avatar
Tabula Rasa

Posts:
784
Group:
Former Staff
Member
#320
Joined:
Jul 26, 2008
I just wrote this up as a quick request, and then after I finished it and posted it for the person I thought I wanted to fix it up a bit and make a better version. This one technically works, but I want to clean it up, and make it automatic.
Right now you have to click something for the words to be counted, and I want to make it so the word count is increasing as you type.
Here's what I have so far:
Code:
 
<script type="text/javascript">
/*Roby/Vitality - Zathyus Network|ZBCode|TCZ*/
if(location.href.match("post/")){
$("#btn_preview").after("<strong>Total Words:</strong><div id='tehcounta'></div><br /><span onclick='countWords()' style='cursor:pointer'>[Count Words]</span>");
function countWords(){
var zbroby=document.getElementById("c_post-text").value.split(" ");
var wcount=zbroby.length;
$("#tehcounta").html(wcount);
}}
</script>

Thanks :D
Offline Profile Goto Top
 
HolySavior Mar 29 2009, 01:41 PM Post #2
Member Avatar
Modifying The World Around You

Posts:
2,488
Group:
Distinguished Coder
Member
#7
Joined:
Jul 2, 2008
Coding language
Everything
use onkeyup :P

what you would do is in jQuery grab the text box you want. than use the onkeyup function and in that function you can run your script area. and display it somewhere :P
Offline Profile Goto Top
 
Vitality Mar 29 2009, 02:17 PM Post #3
Member Avatar
Tabula Rasa

Posts:
784
Group:
Former Staff
Member
#320
Joined:
Jul 26, 2008
No luck yet
Code:
 
<script type="text/javascript">
/*Roby/Vitality - Zathyus Network|ZBCode|TCZ*/
if(location.href.match("post/")){
$("#btn_preview").after("<strong>Total Words:</strong><div id='tehcounta'></div><br /><span onclick='countWords()' style='cursor:pointer'>[Count Words]</span>");
function countWords(){
$("#c_post-text").keyup(function(){
var zbroby=document.getElementById("c_post-text").value.split(" ");
var wcount=zbroby.length;
$("#tehcounta").html(wcount);
});}}
</script>
Offline Profile Goto Top
 
Reid Apr 3 2009, 08:51 PM Post #4
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Vitality
Mar 29 2009, 02:17 PM
No luck yet
Code:
 
<script type="text/javascript">
/*Roby/Vitality - Zathyus Network|ZBCode|TCZ*/
if(location.href.match("post/")){
$("#btn_preview").after("<strong>Total Words:</strong><div id='tehcounta'></div><br /><span onclick='countWords()' style='cursor:pointer'>[Count Words]</span>");
function countWords(){
$("#c_post-text").keyup(function(){
var zbroby=document.getElementById("c_post-text").value.split(" ");
var wcount=zbroby.length;
$("#tehcounta").html(wcount);
});}}
</script>
Try this:
Code:
 
<script type='text/javascript'>
<!--
// insert your copyright here, I guess
$(function(){
if (location.href.indexOf("post/")!=-1) {
$("#btn_preview").after("<span style='font-weight:bold'>Total Words:</span><div id='tehcounta'></div>");
$("#c_post-text").keyup(function() {
$("#tehcounta").html(document.getElementById("c_post-text").value.split(" ").length);
})}})
//-->
</script>


I just wrote this up very quickly so don't expect it to work, and I may have a ton of bugs in there. I'm also sick so I'm not thinking straight either. Lol.

Edit: forgot to close a brace. I tested it on this board here (firebug ftw) and it worked quite nicely.
Edited by Reid, Apr 3 2009, 08:52 PM.
The Resource Board
Offline Profile Goto Top
 
DaMeiN Apr 3 2009, 09:14 PM Post #5
Member Avatar
Oo.SpawN.oO

Posts:
204
Group:
Member
Member
#2,589
Joined:
Mar 16, 2009
Coding language
HTML/CSS
That's pretty sweet, but is there anyway to only accept words, and not just blank spaces?
Posted Image

† You fall to your knees, you beg you plead. Can I be someone else, for all the times I hate myself.. †
† You refuse to bend, so I keep bending until I break... †
Offline Profile Goto Top
 
Reid Apr 3 2009, 11:06 PM Post #6
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
DaMeiN
Apr 3 2009, 09:14 PM
That's pretty sweet, but is there anyway to only accept words, and not just blank spaces?
Yeah, there is. I'm just too lazy to code it. It wouldn't be hard but as I said, I'm sick and thus... blah.
The Resource Board
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Code University · Next Topic »
Locked Topic

Track Topic · E-mail Topic Time: 7:48 PM Jul 10
Hosted for free by ZetaBoards · Privacy Policy