Page 1 of 1

Calcuating the Text Value of Text Box's

Posted: Mon Feb 06, 2012 8:38 pm
by tm1274
I have 2 text fields, the first named Price1 (id 1004), the second named Price2 (id 1006) and a total field named Total (id 1008) and I am trying to create a script to automatically put the total in the Total text field when the user changes the text in one or both of the text fields. I have looked at what I believe to be nearly all change events and have found that the on selectionChanged seems to work best but still not very good. I am trying to script an automatically totaling text field something like this:

Code: Select all

on selectionChanged
     put field id 1004 + field id 1006 into field id 1008
end selectionChanged 
However, the only time it changes is when the user selects the total field and I assume this is due to the script being in this field.

Is there a better simple way of doing this, something that does not require a button to initiate the event and that will automatically change the total based upon the text values in the text fields?

Re: Calcuating the Text Value of Text Box's

Posted: Mon Feb 06, 2012 9:04 pm
by mwieder
I assume this is due to the script being in this field.
That's correct. Put the code into the scripts of the source text fields instead and you should have what you're looking for.

Re: Calcuating the Text Value of Text Box's

Posted: Mon Feb 06, 2012 9:29 pm
by tm1274
Thanks for the fast response.

Ok, by placing the code in the script of both the Price1 and Price2 fields I get a similar result. When I change the text in Price 1 the total does not change until I place my cursor in the Price2 field or if I change the Price2 field the total will not update until the cursor is placed in the Price1 field.

Is there a way to avoid this behavior? I would like to somehow update the total based upon individually updating a text field rather than forcing the user to either click a button or place their cursor in the next text box.

Re: Calcuating the Text Value of Text Box's

Posted: Mon Feb 06, 2012 9:46 pm
by mwieder
Yeah, the selectionChanged event won't trigger until you move from the current field. So you might want to trigger on various key events:

Code: Select all

on keyUp
  recalculate
end keyUp

on backspaceKey
  recalculate
end backspaceKey

on recalculate
  put field id 1004 + field id 1006 into field id 1008
end recalculate


Re: Calcuating the Text Value of Text Box's

Posted: Mon Feb 06, 2012 9:59 pm
by tm1274
That appears to have worked. I have nearly went bald trying to make this work. Thanks for all your help..

Re: Calcuating the Text Value of Text Box's

Posted: Mon Feb 06, 2012 10:52 pm
by mwieder
I have nearly went bald
Not to worry... some of us have trod *that* route beforeyou... <g>