CalcBuilder Forum

Use variables as up and down limits.

User moon_1760 2014-08-20 18:27:11

How can I use variables as up limit, down limit and defaut value into number input?
Thanks.

Moonsoft support 2014-08-21 13:35:01

Hi,
not sure if we fully understand your question, sorry. Where do you have available the variables you need to use? They should be recovered from other inputs of the form? Then maybe we could share with you any js code to modify the validators on fly.

Thanks, regards

User moon_1760 2014-08-21 16:29:13

Yes.
I want use other number input as up and down limits of a number input.
Is it possible?

Moonsoft support 2014-08-21 17:25:49

Yes, then you need to add the proper javascript to your calculator. You will need these functions:


To set maximum or minimum values to a field named 'yourfieldname':

CB( "input" ).rules( "add", {max: 3});

and/or

CB( "input" ).rules( "add", {min: 1});


You only need to replace the name of the field, and maximum or minimum values.

In order to recover a value from another input

var value=CB( "input" ).val();


To remove previos rules added :


CB( "input" ).rules( "remove", "max" );
CB( "input" ).rules( "remove", "min" );



You surely want to change this values when another field changes, so the full function should look like:

CB( "input" ).change(function(){



CB( "input" ).rules( "remove", "max" );
CB( "input" ).rules( "remove", "min" );
var value=CB( "input" ).val();
CB( "input" ).rules( "add", {max: value});

});


Hope this helps, regards

User moon_1760 2014-08-22 17:35:29

Can I use php variables (used in "Code") as down limit or default value?
Thanks.

Moonsoft support 2014-08-23 12:11:01

Hello,

No, because PHP code is executed after the form is validated and submited.

Regards,

...
Support/development

Perfect for small code changes or to correct any bug at your site

Buy now!
...
CalcBuilder

Create dynamic calculators

Buy now!