|
-
Min & Max values in TextInput
Hi there,
Just found this piece of code as I was looking for something on the fly to use for a min and max value for a Input Text Box.
Max value works fine yet I can't work out the min. I was actually looking for two different items here and maybe somebody could help !!!
1) Strait forward max value of 540 sec. and another value of a max and min value of 500 to 540 sec. ???
2) Strait forward min value of 15 sec. and another of a min value of 15 to say 20 sec. ???
Any help would be very much appreciated !! regards aktell
Code:
<mx:TextInput
maxChars="3"
restrict="[0-9]"
change="handleTextChanges(event)"/>
Code:
private function handleTextChanges(evt:Event):void {
var target:TextInput = evt.currentTarget as TextInput;
if(!target) return;
if(parseInt(target.text) > 540) {
Alert.show("You can't enter a number grater than 540");
target.text = "540";
}
}
-
Senior Member
What do you mean with:
and another value of a max and min value of 500 to 540 sec.
Also I would use int instead of parseInt, because it will allow only integer values.
- The right of the People to create Flash movies shall not be infringed. -
-
Hi there,
thanks for the reply. The code was just as I found it!
"Max value works fine yet I can't work out the min."
I was looking how to apply this for min. value as well as the two points below.
1) Strait forward max value of 540 sec. which is as is.
And IF possible I like to find a way where the value can be only include if it is between 500 and 540 sec.
***and another value of a max and min value of 500 to 540 sec. ???***
2) Strait forward min value of 15 sec. same as above.
Same as above.
***and another of a min value of 15 to say 20 sec. ???***
regards aktell
-
Senior Member
Try this for 500-540:
if(int(target.text) > 540 || int(target.text) < 500) {
Alert.show("You can't enter a number greater than 540 or smaller than 500");
if(int(target.text) > 540)
{
target.text = "540";
}
if(int(target.text) < 500)
{
target.text = "500";
}
}
- The right of the People to create Flash movies shall not be infringed. -
-
Hi again,
Thank you for your reply, but unfortunately it does not work as immediately when I type the no.5 into the box the Alert comes up! Tried a few different versions but no. regards aktell
-
Senior Member
You need to eliminate the eventhandler:
change="handleTextChanges(event)"
and add a button eventhandler.
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|