Jump to content

[SOLVED] JS: My word counter hates my edit function


Chezshire

Recommended Posts

Hi -- I know next to nothing about JavaScript, beyond that i think it's neat and wonderful and I'm glad it exists because it does so many wonderful things. That said, my java word counter works really spiffy when you enter something into it. However if you use the edit function to go into a post, all the previously entered text that should be in the 'Messages' window evaporates/vanishes rather then staying put so it can be edited.

 

This is the Javascript i added:

<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 > 9999) {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>

 

This is the PHP which displays the text to be edited when in 'edit post mode'

<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 > 9999) {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>

 

If i use this php, the text does not vanish, but the word counter doesn't display/work when in edit mode.

<tr>
<td align="right" valign="top"><p><b>Message:</b></p></td>
<td><textarea name=CONTENT rows=12 cols=50 wrap=virtual><?php echo $content;
// <br><a href="javascript:DoSpellCheck(window.document.postMessage.CONTENT.value)">[spell Check]</a>
?></textarea></td>
</tr>

 

Any help would be appreciated by everyone on our stupid little homebrewed site.

Thank you very much for stopping and taking the time to look at a novices work.

Thanks

 

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.