Here is a simple tutorial
I have a script object with the John variable with a value of 1

I have a numeric field which in it its initialise event it has
form1.#subform[0].NumericField1::initialize - (JavaScript, client)
this.rawValue = Global.John; //display the variable when the form starts
I have a button which adds 1 to the global variable John when clicked.
form1.#subform[0].Button1::click - (JavaScript, client)
Global.John = Global.John + 1; //add 1 to the variable everytime it is clicked.
I have another numericField and i have a second button which when clicked sends the new John variable value to the numericField.
form1.#subform[0].Button2::click - (JavaScript, client)
NumericField2.rawValue = Global.John;
When form is started, Global.John is displayed in the NumericField

Click +1 button 3 times (variable becomes 4)
Click New John Value Button. The new variable value is displayed in the 2nd numeric field.

I hope this helps