maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Simple Calculation Script

Check out the code behind the Calculate Now button (select button, open Events tab).

The code look like this:
code
var input = Tiggr('baseunit').val();
var from = Tiggr('convertfrom').val();
var to = Tiggr('convertto').val();

var total = input * 0.083;
alert (input + " inches is "+ total + " feet" )
/code

Hope this helps...

wv.wilson75
Posts: 0
Joined: Fri Dec 30, 2011 2:53 am

Simple Calculation Script

Very nice.

I can see how this works and actually understand it a bit.

Is there a line of code that will allow for rounding at a certain decimal place for my results?

wv.wilson75
Posts: 0
Joined: Fri Dec 30, 2011 2:53 am

Simple Calculation Script

One more question.

I see hoe this is calling the input . . . but with a pick list, how can I assign values to each property choice?

How do I assign a value to each measurement type so the var total = input * 0.083; line is modified to show the correct value?

Is this where data mapping would come into play? If so, can you give me a walk through on that too... I can't believe how simple this is once you see how to do it!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Simple Calculation Script

Rounding can be done in JavaScript. For example: http://www.javascriptkit.com/javatuto...

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Simple Calculation Script

[quote:]
How do I assign a value to each measurement type so the var total = input * 0.083; line is modified to show the correct value?
[/quote]
Right now the label and the value are the same thing. We are working on separating them. As a workaround, you could have define labels which match the value or check inside the button action which value was selected and use the appropriate value.

[quote:]
Is this where data mapping would come into play? If so, can you give me a walk through on that too... I can't believe how simple this is once you see how to do it!
[/quote]
No, no data mapping in this case. Data mapping is used when using a service.

wv.wilson75
Posts: 0
Joined: Fri Dec 30, 2011 2:53 am

Simple Calculation Script

No clue what you are talking about , . . could you implement and let me see what you mean . . . I have 26 variations that need to be in the application.

Maybe just add yards conversion to the previous scenario

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Simple Calculation Script

I modified the action to support yards.. check it out.

wv.wilson75
Posts: 0
Joined: Fri Dec 30, 2011 2:53 am

Simple Calculation Script

I am not seeing any changes to the code. Did it maybe not save?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Simple Calculation Script

Not sure what happened, but I restored the screen from history.

wv.wilson75
Posts: 0
Joined: Fri Dec 30, 2011 2:53 am

Simple Calculation Script

I think I got this part now . . . Just a couple of questions and then one more scenario.

var input = Tiggr('baseunit').val();
var from = Tiggr('convertfrom').val();
var to = Tiggr('convertto').val();

if (to == 'Feed'){
var total = input * 0.0833333333333333;
alert (input + " inches is "+ total + " feet" );
}
if ( to == 'Yards') {
var total = input * 0.0277777778;
alert (input + " inches is "+ total + " yard" );

I see that we are converting the "to" in the above lines. What if I need options to change "from" as well as "to"...

I think I will need several lines for this . . . would I need one for every possible combination? And have lines that read something like

if (to == 'Feed')(from == 'Yards'){

I am sorry I am being such a pest.

Return to “Issues”