JavaScript code to include Maximum and minimum limit for a number Z -
function add(id,value) { var x = document. element id(id). value ; x = x.replace('$',''); x = x.replace(',',''); var y = value; var z = +x + +y; document.get element id(id). value =z; }
to set minimum value z 0 , maximium value 999999999
if question how make sure z
never less 0
or greater 999999999
, there 2 common ways:
using
if
:if (z < 0) { z = 0; } else if (z > 999999999) { z = 999999999; }
using
math
:z = math.max(0, math.min(z, 999999999));
math.min(z, 999999999)
pick smallest of values give it, , won't return value greater999999999
. similarly,math.max(0, ...)
return largest of 2 values give it, , won't return value less0
.
Comments
Post a Comment