Keep value in html input box below set amount

I have in input box that can only contain numerical values (with use of [this][1] plugin). Now I want the input to be below, say 90. If a value is entered that exceeds this max cap or cannot be parsed, the previous value should be inserted. By default, the box will contain "1". I imagine I should catch the current value somehow. Try to parse the new value. If it is an allowed value, continue with this value, if not, put the old one back. As my JS skills are really limited I don't even know what events are available to me and I find the documentation I found on the intarwebz rather confusing. --EDIT-- I ended up using [Sergei's][2] code and using [Aaron's][3] usability advice. All I'm looking for now is to enable/disable a whole form's submit. Just disabling a submit button is not enough. [1]: http://itgroup.com.ph/alphanumeric/ [2]: https://stackoverflow.com/questions/630129/keep-value-in-html-input-box-below-set-amount/630228#630228 [3]: https://stackoverflow.com/questions/630129/keep-value-in-html-input-box-below-set-amount/630192#630192
Why do this with javascript? Why not just add maxlength="90" to the input element's attributes?

以上就是Keep value in html input box below set amount的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏