Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

How can I accept only a value valid in my input?

Hello,

I have a input and I suggest a value, for example:

200

this field only must accept a multiply value from itself or divided by itself.

Then

It only can accept: 200 - 400 - 600 - 800 - 900 etc

thanks
Alex
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

Use the mod function

if (fieldvalue % suggestedvalue == 0)
SOLUTION
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

Friend, I don't know much JS, could you give an example how to create this function with a field?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

thanks
Avatar of hidrau

ASKER

Hi Cluskitt,

I notice that If I insert a value 500 it pass and it doesn't.

only value = my suggested value or multiply by itself

I thought you meant only increments of the value or increments of half the value.
Just change the if to:
if (FieldValue % MyValue == 0 || FieldValue == MyValue / 2)