2

hi i have a textbox in html and i want a user to enter the numeric values only which will be for eg. 0,1,2,3,4,5,6,7,8,9,10 and if a user enters 11 it should show an alert box showing "only 0-10 is allowed" since i am a newbie so far i have this script

SCRIPT language=Javascript>

         function validateForm()
         {
             var x=document.form["tst"]["num"].value;
             var y = parseInt( x  ,  10  )
             var i=15;
             if (y>i)
             {
                 alert("Range is Between 0-10");
                 return false;
             }
         }
</script>

here is my textbox code,

  <INPUT  id="num" name="num" onkeypress="return validateForm()" size="2" maxlength="2" type="text" >
2
  • 2
    Why is var i=15; ? dont you need the range between 0-10? Commented Feb 20, 2013 at 13:19
  • yes sorry its my mistake Commented Feb 20, 2013 at 13:27

3 Answers 3

6

You could use an HTML5 input type for ease:

<input type="number" min="0" max="10">

This could potentially remove the need for ghastly modal popups.

Sign up to request clarification or add additional context in comments.

3 Comments

@JanDvorak I really don't care. The OP might.
+1 for "I really don't care. The OP might." thats why we have Tags
sir m need is that the user will input 01 02 03 04 05 06 07 08 09 10 and if he enters 11 or 22 or so on it should restrict it from doing that
1

Try to change var i=15; to var i=11;

Comments

1
<input type="number" name="quantity" min="0" max="10">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.