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

Popular posts from this blog

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -