# Input textfield counter?

**URL:** <https://forum.kirupa.com/t/input-textfield-counter/5280>\
**Category:** Uncategorized\
**Created:** [September 6, 2002, 12:51pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280 "2002-09-06T12:51:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stanley](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Stanley](https://forum.kirupa.com/u/Stanley)\
**Post date:** [September 6, 2002, 12:51pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/1 "2002-09-06T12:51:31Z")

</div>

I am making an input form in flash with a couple of multi-line input textfields. Let’s say they each allow max. 500 char. I have seen textfield charactercounters in javascript. ( “you have xxx characters left”). It’s a nice way to let your users howmuch typing space they have left. But now I am trying to make the same in flashMX, but it’s more compicated than I thought.

It’s easy to substract 1 from a variable every time a key is pressed. But sometimes people use the backspace, so then you detect what key it is, and in case of backslash, add 1 to your var.

But what if somebody selects half a sentence with the mouse and erases the whole chunck with one backspace stroke. How can I detect howmuch characters are gone? Or can I disable the use of mouse in an input textfield?

help !

thanks  
Stanley

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 6, 2002, 1:30pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/2 "2002-09-06T13:30:44Z")

</div>

you would have to have a loop of some kind that goes through and sees how many characters there are…i dont know exactly how to do it though 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 6, 2002, 2:23pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/3 "2002-09-06T14:23:37Z")

</div>

HI,

this should work:

yourTextField.onChanged = function() {  
yourTextField.selectable = false;  
}

Cya

SHO

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 6, 2002, 3:32pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/4 "2002-09-06T15:32:04Z")

</div>

That won’t work eki. If the text area is unselectable, people can not type into it. So if you make it unselectable, it defeats the whole purpose.

You will probably need to become more familiar with the toString commands and such. I don’t know exactly how to do this, if I have time later, I might try something out.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 6, 2002, 3:49pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/5 "2002-09-06T15:49:44Z")

</div>

Hi,

I’m posting a file where it works! it stops working the minute u try to click on the text field, if u don’t touch the mouse it works as usual.

Cya

SHO

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 6, 2002, 5:16pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/6 "2002-09-06T17:16:26Z")

</div>

But what if people want to highlight and select an area? Then they have to start all over.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 6, 2002, 5:59pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/7 "2002-09-06T17:59:30Z")

</div>

Hi,  
But that was what Stanley wanted! Wasn’t it?  
(I mean that he wanted a way of disabling selections in an imput  
text field)

Cya

SHO

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 7, 2002, 6:30am UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/8 "2002-09-07T06:30:20Z")

</div>

why don’t you just use the text lenght property to get the number of chars in it?  
you can use as is, or substract from your allowed max chars to update a dynamic text field with the result to let the user know how many he’s got left.  
of course, this should be included in an on change event handler to update every time the text is changed (as the handler suggests… 😉 )  
if you still can’t get it to work, i can script that for you, just say…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 7, 2002, 6:39am UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/9 "2002-09-07T06:39:20Z")

</div>

reply to eki: he didn’t want to disable the selection of text, but rather to calculate the amout of text selected (in the case of its deletion) then adjust the amout of text left (allowed to be typed) to be displayed accordingly. Unless I am wrong here???

Peace

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 7, 2002, 1:45pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/10 "2002-09-07T13:45:54Z")

</div>

Ok, here’s the examples,  
textfields is counter, other is count down as you wanted.  
It’s all fully commented,  
each swf is only around 500 bytes, as it’s only script…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 7, 2002, 5:11pm UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/11 "2002-09-07T17:11:13Z")

</div>

Very nice eyezburg.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 9, 2002, 11:45am UTC](https://forum.kirupa.com/t/input-textfield-counter/5280/12 "2002-09-09T11:45:13Z")

</div>

Eyezberg, thanks for the fla. Well structured and nicely commented. It is exactly what I was trying to make. I didn’t know a “lenght”-property for a textfield existed. Always nice to learn something new…

greetz  
Stanley
