Jump to content

Word counter stops working if applied twice


Chezshire

Recommended Posts

I'm was hoping that i could apply the following script to two places and that they would both count down  individually. when i apply it to two boxes (both set up as you see below with the script above preceeding the textarea it is to apply to), neither works. But if i get rid of the script from one then the other will work. What do i need to do get these to behave the way i want to so i have a model i can use to apply as many word counters as i want on a page or pages?

 

 

 

<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>

<tr>
	<td width="30%" align="right" valign="top"><p>HISTORY:<br><span class="fineprint">Please describe the character's full history here. The text should be written in the stanard 'third-person' narrative, and be a minimum of 500 words.</p>
</td>
	<td valign="top"><textarea name=HISTORY cols='55' rows='35' wrap='virtual' 
	onKeyDown="wordCounter(this.form.Q3367,this.form.remLen,500);" 
	onKeyUp="wordCounter(this.form.HISTORY,this.form.remLen,500);"><?php echo $record["history"]; ?></textarea><br><span class='fineprint'>Words remaining: <input type='text' readonly name='remLen' size='5' value='500'></span><br><INPUT TYPE="reset" VALUE="Reset" id=reset1 name=reset1></td></tr></textarea></td></tr>

</table>

 

 

Also why did this forum make me make a poll so i could post?

Link to comment
Share on other sites

Thanks -- I'm researching and testing it too

 

And i don't get why it doesn't work: In my edit page, i have the JS, followed by the text area i want to count text on, and then i do the same thing again which i plug the JS in again and then the textarea i want to count text in.

 

I thought that would work but it doesn't and i don't know why and it makes me sad - thanks for any help you can give.

-Chez

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.