Question: This html form and the related php code works pretty well together. I need to add a word counter. Any suggestions. 

```
<form action="form.php" method="POST">

<fieldset>

   <input type="hidden" name='counter' value='2'/>

  <p><label for="heading1"></label>
  <input type="text" name="heading1" size="60" /></p>
  <p><label for="input1"></label>   
   <textarea cols="width" rows="height" name="input1">...</textarea></p>

   <p><label for="heading2"></label>
   <input type="text" name="heading2" size="60" value="first para title..."></p>
   <p><label for="input2"></label>
   <textarea cols="width" rows="height" name="input2">...</textarea></p>

<br />
<fieldset>
<input type="submit" value="" />
<input type="reset" value="" />
</fieldset>
</form>

```

The related php code is found below.

```
<?php

$count=$_REQUEST['counter'];

for($i=1;$i<=$count;$i++)
{
echo "<p>" . $_REQUEST['heading'.$i] . "</p>";
echo "<p>" . $_REQUEST['input'.$i]. "</p>";
}

?>  

```

Answer: 
Example:

```
<textarea name="input1" onkeyup="window.alert(document.getElementsByName('input1')[0].value.trim().split(' ').length);"></textarea>

```
Use javascript, with an event on the change in the textarea(s).
Then you count the word when typing and update the counter.