+1
Beantwoord

How can I add multiple text field inputs together then divide?

tate hayes 11 jaar geleden bijgewerkt door icahill (Administrator) 11 jaar geleden 5
I have 4 text fields, that use a number pad keyboard. I want take the average of all of the inputs from the field, then divide by the number of inputs (there are 4). How would I do this? I'm not very familiar with the action tags on Rarewire, by the way.
This can be accomplished using a series of assign tags and our evaluations.

Your assign tags will serve to capture the contents of the textfield like so:

<action name="capturefieldvalues">
<assign property="var:textfield1" value="[object:TEXTFIELDALIAS1.text]"/>
<assign property="var:textfield2" value="[object:TEXTFIELDALIAS2.text]"/>
<assign property="var:textfield3" value="[object:TEXTFIELDALIAS3.text]"/>
<assign property="var:textfield4" value="[object:TEXTFIELDALIAS4.text]"/>
</action>


Object properties for the text attribute of your textfields can be assigned as above. Once you have variables stored for these fields then you can use an eval to average them out and display in a 5th total textfield. Evals are simply javascript computations and can perform simple math very easily.


<action name="populateaverage">
<assign property="object:TOTALFIELDALIAS.text" value="[eval:([var:textfield1]+[var:textfield2]+[var:textfield3]+[var:textfield4])/4]" />
</action>
Thanks Ian, that fixed it! I have another question about keyboards. How can you code the panel, so that you can scroll down to the bottom of the app when the keyboard is up? Right now, the keyboard covers the bottom half of the panel and I can't close it.
This will be determined by the UI that you build underneath the keypad. In some instances we have built apps that reposition the xpos and ypos up when the keypad is opened or you could consider wrapping your content in a pager to allow it to scroll up. This is always hard to workaround on iphones because there is not a dismiss keyboard button like there is on the iPad and Android.
Okay, so how do I assign a certain button to be the match to the flame, per se. More or less, I want to assign an "enter" or "calculate" button to cause the calculations.
Have you had a chance to look through our tutorials?

https://studio.rarewire.com/wordpress...

This tutorial will introduce you to action triggers or on's. Adding an onclickup or onhover type attribute to your button object allows you to choose the action that is initiated.