Jump to content

WORDCOUNT - Keeps breaks when i try to incorporate it to my site - HELP!


Chezshire

Recommended Posts

OBLIGATORY HEARTFELT THANKFULNESS -

Hi and to anyone reading this, thank you for at least taking a peek at my problem. And to anyone with a suggestion, doublely thanks.

 

I'm very new to the whole PHP scene and still learning and honestly don't know my elbow from my a-hole when it comes to this stuff. But what little i do know fascinates me and motivates me to continue trying to push myself to see what I can accomplish. I've posted to this forum once before and while I didn't get a solution, i was set in a direction that lead me to one and I want to thank all those again who helped me. Thank you!

 

MY PROBLEM - MY WORD COUNT BREAKS when i try to incorporate it to my site so people will know if they are posting an acceptable length post or not.

 

MY GOAL - To make the live counter count down or count up as people type so they know if they've written a post which is at least 200 words. Currently the box which is marked 'Message:' doesn't work, but the box below it which is my test does.

 

Here is my code:

<tr>
<td align="right" valign="top">
<p><b>Message:</b><br>
<span class='fineprint'>Posting Instructions here.</span>
<td valign="top"><textarea name=CONTENT rows=12 cols=50 wrap=virtual 
onKeyDown="wordCounter(this.form.Q3367,this.form.remLen,200);" 
onKeyUp="wordCounter(this.form.Q3367,this.form.remLen,200);">
</textarea>
<br><span class='fineprint'>Words remaining: 
<input type=box readonly name=CONTENT size=3 value=200></span><br>
<INPUT TYPE="reset" VALUE="Reset" id=reset1 name=reset1></td></tr>
</textarea></td>
</tr>


<td align="right" valign="top">
<p><b>Test Box:</b><br>
<span class='fineprint'>Posting Instructions here.</span>
<td valign="top"><textarea name="Q3367" rows=12 cols=50 wrap=virtual  onKeyDown="wordCounter(this.form.Q3367,this.form.remLen,200);" 
onKeyUp="wordCounter(this.form.Q3367,this.form.remLen,200);">
</textarea>
<br><span class='fineprint'>Words remaining: 
<input type=box readonly name=remLen size=3 value=200></span><br>
<INPUT TYPE="reset" VALUE="Reset" id=reset1 name=reset1></td>
</tr>

 

 

 

<SCRIPT language="javascript">
//  Live Word Count Script - added May 2nd -->


function wordCounter(field, countfield, maxlimit) {
wordcounter=0;
for (x=0;x<field.value.length;x++) {
      if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
      if (wordcounter > 250) {field.value = field.value.substring(0, x);}
      else {countfield.value = maxlimit - wordcounter;}
      }
   }

function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
      else
      {countfield.value = maxlimit - field.value.length;}
  }
//  End -->
</script>

 

 

 

here is the script i've thatched together to help with this process

[code]
<SCRIPT language="javascript">
//  Live Word Count Script - added May 2nd -->


function wordCounter(field, countfield, maxlimit) {
wordcounter=0;
for (x=0;x<field.value.length;x++) {
      if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
      if (wordcounter > 250) {field.value = field.value.substring(0, x);}
      else {countfield.value = maxlimit - wordcounter;}
      }
   }

function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
      else
      {countfield.value = maxlimit - field.value.length;}
  }
//  End -->
</script>

 

Once again thank you to anyone who can help me with this. I'm befuddled and off to drink myself silly which won't be hard as i'm so so so tired right now.

Cheers![/code]

Link to comment
Share on other sites

Thank you for moving my post to the correct forum Barand. Sorry for posting to the incorrect forum prior that is my bad and I will try not to do so again in the future.

 

I've tried executing your suggestion, and the wordcount is still not working  :'(

I've tried changing the word 'form' in the onKeyDown and onKeyUp to 'testarea' hoping that that might have been my issue, but that didn't work either.

 

This is currently how my code looks:

 

<tr>
<td align="right" valign="top">
<p><b>Message:</b><br>
<span class='fineprint'>Posting Instructions here.</span>
<td><textarea name=CONTENT rows=12 cols=50 wrap=virtual 
onKeyDown="wordCounter(this.form.Q3367,this.form.remLen,200);" 
onKeyUp="wordCounter(this.form.Q3367,this.form.remLen,200);">
</textarea>
<br><span class='fineprint'>Words remaining: 
<input type=box readonly name=Q3367 size=3 value=200></span><br>
<INPUT TYPE="reset" VALUE="Reset" id=reset1 name=reset1></td></tr>
</textarea></td>
</tr>

 

 

Any suggestions, pointer, explanations or fixes are very welcomed. And as always thanks to everyone for this great forum - it's really helpful to newbies like me!

 

Link to comment
Share on other sites

Thank you very much Barand

 

I should have slept more first before trying, drunkin' a little less and been more patient - lesson learned (Hopefully  :P). Thank you very very very much. My friends will be so pleased.

 

Question is it ok to 'link' to this site? I.E. to put a 'link' in one's own links referring to places and or resources they think are cool and worth exploring?

 

Thanks for helping me to solve my problem again oh sexy php and scripting god that you are!

 

-M

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.