Input limit

Discussion in 'JavaScript' started by Jonathan_S, Mar 1, 2008.

  1. #1
    Hm... can anyone help med how I can limit a form input to not be more than a specific value? For instance you should not be allowed to type in a number more than 1826. Is this possible to do in some way? Please help!

    Thank you for your support
     
    Jonathan_S, Mar 1, 2008 IP
  2. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #2
    Try this...

    
    <html>
    <head>
    <script type="text/javascript">
    function limit(element, num) {
    	if (element.value>=num)	element.value = num;
    }
    </script>
    </head>
    <body>
    <input type="text" name="someNumber" maxlength="4" onkeydown="limit(this, 1826)" onblur="limit(this, 1826)" />
    </body>
    </html>
    
    HTML:
    Hope that helps somehow. :)
     
    rkquest, Mar 1, 2008 IP