i have javascript function fires on change of html form field adds decimal (.0) inputted number , checks value entered between 1 , 100. works fine need alter function check decimal inputted either .0 or .5 , refuse if not match. code:
function wingsetdecimal(input) { input.value = parsefloat(input.value).tofixed(1); if (input.value <1 || input.value >100) { alert("wing length value above or below limits"); // accept value , not reset field // input.value =''; } }
i don't know how approach issue check if decimal part .0 or .5. in other words field should reset input.value =''
if value inputted is, example 10.4 accepted if 10.0 or 10.5. have tried string.indexof(".")==-1;
no success.
just 2 cents, perhaps trick:
if ((input.value % 1) * 10 === 0 || (input.value % 1) * 10 === 5) { // logic comes 'ere }
or derek has pointed out in comments, works in ever shorter form:
if(!(input.value % 0.5)) { // todo }}
Comments
Post a Comment