• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to make a count down of Characters in a textbox?

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to make something where when you start typing in a textbox you see the characters count down telling the user how many characters they got left.

I got it sort of working but not 100% yet. When you start typing the count goes down and when you hit the backspace the count goes up.

The thing that I have not been able to get is if they Use "ctrl + a" or Highlight a line to restore that count.

So if they select 5 character at once and they hit delete then the count would get +5. Mine just does +1 since I did it on keypress Down.

Here is my code- I am using Jquery by the way.

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be using the length of the text in the textbox and not some counter. aka... maxNumber - myBox.length

Eric
 
Michael Hubele
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eric Pascarello:
You should be using the length of the text in the textbox and not some counter. aka... maxNumber - myBox.length

Eric



countDown is my maxNumber. I set it to 500. and I get the length of the textbox.
 
Michael Hubele
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I have so far. It now takes in account of selection deletes but now working on copy and paste.


 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I was saying is that you do not have to deal with what keystrokes a user hits You just need to know the length [number of characters in the textbox] and the max number that is allowed.

So you do not have to sit there and check to see if it is a basckspace or not since the textbox length will tell you.

 
Michael Hubele
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain what is going on? I don't understand much of that code.
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic