View Full Version : maximum number in an input text box
moozy
March 12th, 2009, 12:12 PM
Hello I am new.
Could anyone tell me how to limit the maximum number you could put in an input textbox?
I want the maximum to be 10 and the minimum to be 0.
Thank you in advance
glosrfc
March 12th, 2009, 12:49 PM
This is how I would go about it in AS2. You should be able to adapt it easily enough:
theText.maxChars = 2;
theText.restrict = "0-9";
theText.onChanged = function () {
if (Number(theText.text) > 10) {
theText.text = "";
}
}
Because you've restricted the input to numbers (i.e. the user can't input -) there's no need to check for a minimum value.
moozy
March 12th, 2009, 01:12 PM
thank you! I will have a play, it seems to be the onChanged that the error compiler is picking up on
moozy
March 12th, 2009, 01:20 PM
sorted it, thanks very much! I used
myTextField.maxChars = 2;
myTextField.restrict = "0-9";
myTextField.addEventListener(Event.CHANGE, none);
function none(e:Event):void
{
if (Number(myTextField.text) > 10) {
myTextField.text = "";
}
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.