jquery: set min max input in option type number -
i have part of code
<input type="number" min="2" max="10" step="2" id="contact" oninput="new_sum"> in field can insert number > 10 , < 2.
how can limit it?
add onchange function , set value if it's out of range.
html:
<input id="numberbox" type="number" min="2" max="10" step="2" id="contact" oninput="new_sum" /> jquery:
$(function () { $( "#numberbox" ).change(function() { var max = parseint($(this).attr('max')); var min = parseint($(this).attr('min')); if ($(this).val() > max) { $(this).val(max); } else if ($(this).val() < min) { $(this).val(min); } }); }); example: http://jsfiddle.net/ddk67/75/
jquery numbers max min
No comments:
Post a Comment