|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Wizard
![]() Join Date: Sep 2001
Location: Singapore
Posts: 5,332
|
Looking for a textarea word count bookmarklet
Yeap title says it all: I've managed to find a character count bookmarklet but that is pretty much useless to me right now. I've also found one that reports the number of words in the selection.
If someone has come across one, let me know. And yes I've Googled for it ![]() |
|
|
|
|
|
#2 |
|
Web-coding NINJA!
![]() Join Date: Jul 2002
Location: Dallas, TX
Posts: 2,910
|
Do you want it to prompt you for anything, like the name/id of the textarea? Or do you just want it to find a textarea arbitrarily?
|
|
|
|
|
|
#3 |
|
SitePoint Wizard
![]() Join Date: Sep 2001
Location: Singapore
Posts: 5,332
|
Don't tell me you're thinking of writing one for me again?
![]() I'm thinking of something like the character count bookmarklet where the no. of characters appear next to every textfield or textarea it can find and change as you type. Though in reality there would be only 1 textarea that matters so having it work on just that one (probably using getElementsByTagName("textarea") would be enough). |
|
|
|
|
|
#4 |
|
Web-coding NINJA!
![]() Join Date: Jul 2002
Location: Dallas, TX
Posts: 2,910
|
Did I already write one for you? *bad memory*
Can you link me to the two you've already found? |
|
|
|
|
|
#5 |
|
SitePoint Wizard
![]() Join Date: Sep 2001
Location: Singapore
Posts: 5,332
|
Yup you did - remember the one for incrementing the fields after a particular one is changed?
http://www.squarefree.com/bookmarklets/forms.html has the character count one... I can't find the count words in selection one now, but I'll post the code Code:
/* count words in selection */
EhV3eT8s=document.getSelection().replace(/\s/g,' ').replace(/ {2,}/g,' ').replace(/ $|^ /g,'').split(' ');
if(EhV3eT8s!=''){alert(EhV3eT8s.length+' words in selected text')}else{alert('Select some text first!')}
|
|
|
|
|
|
#6 |
|
Web-coding NINJA!
![]() Join Date: Jul 2002
Location: Dallas, TX
Posts: 2,910
|
Oh ya, I remember that. I guess I was thinking of bookmarklets in particular.
It was pretty easy to modify that character count one, only two lines of the code needed to change. javascript:(function(){var D=document,i,f,j,e;for(i=0;f=D.forms[i];++i)for(j=0;e=f[j];++j)if(e.type=="textarea" )S(e);function S(e){if(!e.N){var x=D.createElement("span" ),s=x.style;s.color="green";s.background="white";s.font="bold 10pt sans-serif";s.verticalAlign="top";e.parentNode.insertBefore(x,e.nextSibling);functi on u(){l=e.value.split(/[\s\n]+/).length;x.innerHTML=(e.value=='')?0:l;}u();e.onchange=u;e.onkeyup=u;e.oninput =u;e.N=x;}else{e.parentNode.removeChild(e.N);e.N=0;}}})() Works on the page I tested it on |
|
|
|
|
|
#7 |
|
SitePoint Wizard
![]() Join Date: Sep 2001
Location: Singapore
Posts: 5,332
|
Thanks once again!
You're starting to become my JavaScript angel from heaven ![]() |
|
|
|
|
|
#8 |
|
Web-coding NINJA!
![]() Join Date: Jul 2002
Location: Dallas, TX
Posts: 2,910
|
I'm here to help
![]() You're quite welcome. |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 21:03.











Linear Mode
