javascript - Jquery input number in multiples (keyup) -
how can make input
element accept numbers in multiples of 50?
i know can specify step="50"
attribute, prefer solution triggered the keyup
event.
i found code, prevents users entering number less 50.
question : how can adjust code multiples of 50 can entered ?
$('#numberbox').keyup(function(){ if ($(this).val() < 50){ alert("minimum quantity: 50"); $(this).val('50'); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="numberbox" type='number'>
use modulo operator
var multiple = 50; $('#numberbox').keyup(function(){ if (parseint($(this).val()) % multiple ) { alert("only multiples of " + multiple + " allowed"); $(this).val(multiple); } });
Comments
Post a Comment