DotDragnet
May 24, 2012, 08:33:26 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Simple javascript character counter  (Read 291 times)
Steve Lampkins
Hero Member
*****
Posts: 1327


OOH! *TITTER*


View Profile Awards
« on: November 24, 2011, 11:20:13 AM »

I have a very simple set of forms that you can use to count the number of characters you enter.

Works well, but I'd rather it were dynamic, so I don't have to click a button.

Also, wrapping a div around the forms, to try and get a background colour (CSS-styled), breaks the first form. No idea why.
EDIT: fixed that, I wasn't properly closing my styling mark up in the div

Any help? Want to keep it simple.


<script language="JavaScript">
function countit(what){
formcontent=what.form.charcount.value
what.form.displaycount.value=formcontent.length
}
</script>


Then three of these in a row:

<form method="POST">
<input type="text" name="charcount" size="75" style="font-family: Courier New; font-size: 10pt;">
<input type="button" onClick="countit(this)" value="Count" style="font-weight:bold; font-size: 10pt;">
<input type="text" name="displaycount" size="3" style="font-weight:bold; font-size: 10pt; text-align:center;">
</form>


« Last Edit: November 24, 2011, 11:29:17 AM by Steve Lampkins » Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 551



View Profile Awards
« Reply #1 on: November 24, 2011, 11:34:10 AM »

<input type="text" name="charcount" onkeyup="countit(this)" onchange="countit(this)" ...
Logged
Steve Lampkins
Hero Member
*****
Posts: 1327


OOH! *TITTER*


View Profile Awards
« Reply #2 on: November 24, 2011, 11:55:27 AM »

Couldn't get much simpler than that. smile Thanks a bunch!!
Logged
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #3 on: November 25, 2011, 10:02:54 AM »

I built a character counter a while ago but I don't think it was as simple as this one. I shall thus steal it, and use it as if it were my own!

#CowboyDeveloper
Logged

Steve Lampkins
Hero Member
*****
Posts: 1327


OOH! *TITTER*


View Profile Awards
« Reply #4 on: November 25, 2011, 01:07:14 PM »

I'm sure everyone already knows you are simple.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!