NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: Edward on June 19, 2008, 02:07:36 am



Title: Field control with minimum and maximum
Post by: Edward on June 19, 2008, 02:07:36 am
I have a variable which I want to be controlled by 2 controls, a field and a slider control.
The slider control can be given a minimum and a maximum value. This is what I want.
To give the user the opportunity to give the variable an exact value, I have also introduced a field control. The problem is that the field control can't be given a minimum and a maximum value. I can use code to check the value, but I don't know how to undo the new value.

Anyone an idea to get this working?


Title: Re: Field control with minimum and maximum
Post by: Fu-Kwun Hwang on June 19, 2008, 03:48:36 pm
if the variable is f, and the minimum and maximum you want is fmin, fmax
You can add the following to the action field for the numerical input textfield element

if(f<fmin)f=fmin;
else if(f>fmax)f=fmax;

Is that the logic you want. Just try to express your login into formula/equation.


Title: Re: Field control with minimum and maximum
Post by: Edward on June 20, 2008, 03:56:18 pm
Yes, this is what I wanted.
Thanks for this very simple solution.