Allowing Only Certain Numbers and/or Increments of Numbers In Form Field
I have a form field which only allows increments of 25 to be entered into the form field, but now I need it to also allow the number 0. Here is the existing code:
It rounds up or down to the nearest increment of 25. So if someone types in 60, it'll round down to 50. Unfortunately, if someone types in 0, it rounds up to 25 as it is set now.
I hate to push my luck but I have a similar code that allows an increment of 12 as long as it's 12 or 24, and then anything over 25 it rounds up or down to the nearest 25 increment like the other code did. Is there a way to make this allow a zero as well?
HTML Code:
<input type="text" size="4" onChange="var n = parseInt(0 + this.value, 10), x = n <= 50 ? 12 : 25; this.value = Math.max(Math.round(n / x) * x, 12);" name="product_qty" value="12" />
Bookmarks