Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Only Allow Certain Amount in Textbox Input

    Hi is there a way to only allow a certain numeric amount to be entered into a text input? i.e, Like nothing over 20?

    Thanks

  • #2
    New Coder
    Join Date
    Mar 2010
    Location
    New Jersey USA
    Posts
    81
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by theflyingminstr View Post
    Hi is there a way to only allow a certain numeric amount to be entered into a text input? i.e, Like nothing over 20?

    Thanks
    Yes. Check Post number 10 from Philip M.
    http://codingforums.com/showthread.php?t=207805

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nifty, thanks!

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Well, if we are talking about one textbox only it is simple:-

    Code:
    <input type = "text" id = "mytextbox" size = "2" maxlength = "2" onblur = "chk(this)">
    
    <script type = "text/javascript">
    
    function chk(which) {
    var val = which.value;
    if (val > 20) {
    alert ("The maximum value allowed is 20");
    which.value = "";
    setTimeout("document.getElementById('" + which.id + "').focus()", 25);
    }
    }
    </script>

    "To get back my youth I would do anything in the world, except take exercise, get up early, or be respectable." - Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •