Link to home
Create AccountLog in
Avatar of LelloLello
LelloLello

asked on

Calculate and display the number of characters within a TEXTAREA

I have the following code

<form method="POST">

<table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="100%">
<textarea rows="12" name="charcount" cols="60" wrap="virtual"></textarea>
      </td>
    </tr>
    <tr>
      <td width="100%"><div align="right"><p><input type="button" value="Calculate Characters"
      onClick="countit(this)"> <input type="text" name="displaycount" size="20"></p>
      <div align="center"><center><p>This free script provided by
      <a href="http://javascriptkit.com">JavaScript
      Kit</a></p>
      </center></div></div></td>
    </tr>
  </table>

</form>

<script language="JavaScript">

function countit(what){

//Character count script- by javascriptkit.com
//Visit JavaScript Kit (http://javascriptkit.com) for script
//Credit must stay intact for use

formcontent=what.form.charcount.value
what.form.displaycount.value=formcontent.length
}
</script>
Avatar of LelloLello
LelloLello

ASKER

I'd like to modify to calculate the number of click that user click and show it in a textfield ?

Please check my code sample at http://jsfiddle.net/vMwQ8/
Sudaraka,
http://blog.wardelldesign.com/wp-content/uploads/rollover/rollover.html 
Very good, One small issue missing could you please add to it a function to have an interactive button with the roll over action and roll out using a button class.

<form method="POST">
    <input type="button" value="Calculate Clicks"
      onClick="countit(this)">
    <input type="text" name="displaycount" size="20">
</form>

function countit(what){
    var current_count = parseInt(what.form.displaycount.value);
    if(isNaN(current_count)) current_count = 0;
   
    what.form.displaycount.value = ++current_count;
}

ASKER CERTIFIED SOLUTION
Avatar of Sudaraka Wijesinghe
Sudaraka Wijesinghe
Flag of Sri Lanka image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer