SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did I already write one for you? *bad memory*

    Can you link me to the two you've already found?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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);function 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
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  7. #7
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks once again!

    You're starting to become my JavaScript angel from heaven

  8. #8
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm here to help

    You're quite welcome.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •