CalcBuilder Forum

Set default value

User moon_1760 2014-09-03 20:26:30

How can I set default value into number input using another number input?
Thanks.

Moonsoft support 2014-09-03 20:34:54

Hi,
in order to set field values dynamically you must use javascript section to capture the event of the first field changing and assign a new value to the destination field, this code should be placed at the first js tab of your calculator, replacing yourfirstfieldname and yoursecondfieldname with the right field names at your form:

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

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

CB("input").val(newvalue);

});

Hope this helps, regards

Moonsoft support 2015-11-16 18:16:31

hi i want the same as above but from an inline field to a text field default value that can be changed by the user.

Moonsoft support 2015-11-17 10:52:57

Hi,
that is more complex, as you can't capture the event of the inline result being changed, because it's done internally by the calculator script. As a workaround, you can use other field change event, wait sometime until the inline field has the new value and then use it. The structure would be:


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

setTimeout(function(){
var newvalue=CB("div").html();

CB("input").val(newvalue);

}, 3000);

});


replacing

yourfirstfieldname
yourinlinefieldname
yoursecondfieldname

with your calculator fields. You can create more sections with the same structure and other 'yourfirstfieldname' in order to attach it to more input fields.


This is not an optimal solution as you're waiting 3sg for the result, you must ensure this is enough for the calculator returning the proper value to the inline, you should increase this time if required.


Hope this helps, regards

Edited by MSTeam - 18.11.2015 18:54

...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!
...
Support/development

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

Buy now!