javascript - Maxlength limit for onClick button input -


i'm creating simple form allow customers input number form field, should have limit of 6 characters.

the numbers submitted our database, customer needs see them before submitting.

i have used script below create number submission form input text field (which can sent db). went method majority of our audience on on mobiles, didn't think standard text field input user friendly (open alternatives on this).

<input name="ans" type="text" size="6" maxlength="6"><br> <p><input type="button" value="1" onclick="document.calculator.ans.value+='1'"> <input type="button" value="2" onclick="document.calculator.ans.value+='2'"> <input type="button" value="3" onclick="document.calculator.ans.value+='3'"></p>  <p><input type="button" value="4" onclick="document.calculator.ans.value+='4'"> <input type="button" value="5" onclick="document.calculator.ans.value+='5'"> <input type="button" value="6" onclick="document.calculator.ans.value+='6'"></p>  <p><input type="button" value="7" onclick="document.calculator.ans.value+='7'"> <input type="button" value="8" onclick="document.calculator.ans.value+='8'"> <input type="button" value="9" onclick="document.calculator.ans.value+='9'"></p>  <p><input type="button" value="0" onclick="document.calculator.ans.value+='0'"> <input type="reset" value="reset"></p> <p><input type="submit" name="submit" value="submit"></p> 

the maxlength function doesn't work when numbers added 'ans' input in way , have tried js , jquery solutions, , 1 can find replaces input error after character limit has been exceeded - rather limit number of inputs user can add.

can help?

thanks

steve

you can more use type="number" or type="tel" allow mobile users enter numbers. bring "keypad", tried create here:

<input type="number" max="999999"> <input type="tel" max="999999"> 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -