auto update a field based on two other fields values

Solved
ML
Mat Lawrence
Versilia Solutions Ltd

Hi,

I would like to do the following:

Have a Label with a number say 10

Have a text box with user entry numeric only 0-10

Have another text box with user entry numeric only which equals the label value minus the text box value

i.e. 10 - 5 = 5

Seems a pretty straightforward feature but I can't figure out how to do it?

Any help would be appreciated.

Thanks

Mat

7 years ago
SOTI Snap
ANSWERS
S
SMod@Soti
7 years ago

 Hi Mat,

This can be accomplished using JavaScript.

For example,

Add the label with the fixed numeric value (say 10)

Set the ID of the first textbox to 'v1' (you can use any name)

Add the second textbox and set its ID to 'v2'

Now for the first textbox v1, go to events and from the drop down for events, select OnBlur and 'Run JavaScript' as the action.

Open the Script Editor and paste the following code:

document.getElementById("v2").value = 10 - document.getElementById("v1").value;

The logic behind this is as follows:

The user enters a value in textbox 1 (v1) and when they leave the textbox 1 (blur) the javascript code takes the value in textbox 1 and subtracts it from 10 and assigns it to textbox 2 (v2).

Feel free to change the fixed variable from 10 to any other number.

Please let me know if you have any questions.

Thanks

Solution
PH

Is there also a way to count the values of 2 fields?  tried to use the sum command and "+"

PH

already solved it

"

function sum(x,y){
    return parseFloat(x, 10) + parseFloat(y, 10);
}


    var value1 = document.getElementById('v1').value,
    value2 = document.getElementById('v2').value;

    var value3=document.getElementById('v3').value = sum(value1, value2);

"

ML
Mat Lawrence
7 years ago

Worked perfectly! Thank you so much. Is there a reference guide online for the Javascript?

Regards

Mat

S
SMod@Soti
7 years ago

There is no official reference guide for JavaScript commands but all the general statements and commands should work as expected in SOTI Snap.

Please let me know if any further information is required.