Page 2 of 3

Simple Calculation Script

Posted: Mon Jan 02, 2012 1:15 am
by maxkatz

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...


Simple Calculation Script

Posted: Mon Jan 02, 2012 3:35 am
by wv.wilson75

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?


Simple Calculation Script

Posted: Mon Jan 02, 2012 3:39 am
by wv.wilson75

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!


Simple Calculation Script

Posted: Mon Jan 02, 2012 4:39 am
by maxkatz

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


Simple Calculation Script

Posted: Mon Jan 02, 2012 4:41 am
by maxkatz

[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.


Simple Calculation Script

Posted: Mon Jan 02, 2012 5:29 am
by wv.wilson75

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


Simple Calculation Script

Posted: Mon Jan 02, 2012 7:53 pm
by maxkatz

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


Simple Calculation Script

Posted: Tue Jan 03, 2012 12:52 am
by wv.wilson75

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


Simple Calculation Script

Posted: Tue Jan 03, 2012 1:49 am
by maxkatz

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


Simple Calculation Script

Posted: Tue Jan 03, 2012 2:17 am
by wv.wilson75

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.