hidrau
asked on
I need a function in Javascript that can valid my value
Hello Guys
I have a value and this value is the minor value, for example:
20
The user will enter with its value, for example: 55
The function must check if the value is a multiple of 20, then, the system can only accept
20, 40, 60, 80, 90...
If the user enter with 55, the system must indicate a valid upper value, for example : 60
if the user enter 71 the system must appoint the upper valid value of 80.
Function checkValue(valueMinor, ValueUser){
}
thanks
I have a value and this value is the minor value, for example:
20
The user will enter with its value, for example: 55
The function must check if the value is a multiple of 20, then, the system can only accept
20, 40, 60, 80, 90...
If the user enter with 55, the system must indicate a valid upper value, for example : 60
if the user enter 71 the system must appoint the upper valid value of 80.
Function checkValue(valueMinor, ValueUser){
}
thanks
I don't think that will do it.
I think it needs to be a little more complicated, perhaps something like this
I think it needs to be a little more complicated, perhaps something like this
<html>
<body>
<script type='text/javascript'>
function checkValue( valueMinor, ValueUser ) {
var result = 0
try {
var user = parseInt( ValueUser )
var low = user - valueMinor
var rem = low % 20
result = ( user - rem ) + ( ( rem > 0 ) ? 20 : 0 )
} catch(e) {}
alert( 'result: ' + result )
return result
}
</script>
<input type=text onchange='checkValue(20,this.value)'>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think they wants to be able to supply the min value so that it can be something other than 20.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks very much
Open in new window