A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Min & Max values in TextInput

  1. #1
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    117

    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";
    }
    }

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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. -

  3. #3
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    117
    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

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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. -

  5. #5
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    117
    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

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center