Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

javascript function to allow 2 or 3 numeric

Is there a java script function if I allowed 2 digit numbers and if I hit or added 3 digit numbers can i get a popup saying allow or disallow for example.
Avatar of ronan1979
ronan1979

use the handler "onChange" and then check the length of the string
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<< if I hit >> 

I would replace line 15 of @HonorGod's code by :


2 digit number: <input type='text' onkeyup='verify(this)' onclick='verify(this)' >

Open in new window

If the idea is to disallow anything greater than 2 digit numbers, then simply add the max length property to the text box to 2 i.e maxlength = 2 and save user the trouble of entering more digits in the first place.

if you also need to make sure there are two digits compulsorily, Honorgod's example is the perfect one. I would not recommend leakims method for the reason it will annoy the user by showing alert every time anything is entered, at least I get annoyed.
Avatar of Seven price

ASKER

Understandable >> Kadaba

But I want it to ask me to allow the 3rd digit before actually implementing or showing it in the text box is that possible with Honorgod's method not to sure. And if not allow have a disallow kind of ok and cancel i can do that part.

 but the method to actually stop the user from adding 3 digits before displaying it.

So for example a user types 2 digit no problem then he hits the button again but before the digit goes a pop up ask yes or no what ever and if the user hit yes then the digit adds in. making it 3 digits.
tks
Thank you for the grade & points.

Good luck & have a great day.