Page 3 of 3

Simple Calculation Script

Posted: Tue Jan 03, 2012 2:22 am
by maxkatz

Yes, it would have to be every combination. Something like this:

code
if (to == 'Inches') {
if (from == 'Feed'){
...
}
else if (from == 'Yards') {
...
}

}
else if (to=='Yards') {
if () {
...
}
else if () {
...
}
...
}
/code


Simple Calculation Script

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

Thanks. . . I am going to play around with this and see if I can make it work . . . I truly appreciate all your help on this.


Simple Calculation Script

Posted: Tue Jan 03, 2012 2:46 am
by maxkatz

You welcome.. glad to help.


Simple Calculation Script

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

So here is what I tried . . . now nothing is working. Can you look and see what I have done wrong here. I am sure it is obvious.

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

if (from == 'Acres') {
if (to == 'Acres'){
var total = input * 0;
alert ( " ERROR: You are converting to the same unit of measurement! ");
}
else if (to == 'Poles / Perches / Rods'){
var total = input * 160;
alert (input + " acres equal "+ total + " Poles, Perches or Rods" );
}
else if (to == 'Square Feet') {
var total = input * 43560;
alert (input + " acres equal "+ total + " Square Feet" );
}

}

if (from == "Poles / Perches / Rods') {
if (to == 'Poles / Perches / Rods'){
var total = input * 0;
alert ( " ERROR: You are converting to the same unit of measurement! ");
}
if (to == 'Acres'){
var total = input / 160;
alert (input + " Poles, Perches or Rods equal "+ total + " Acres" );
}
else if (to == 'Square Feet') {
var total = input * 43560;
alert (input + " Poles, Perches or Rods equal "+ total + " Square Feet" );
}

}

if (from == "Square Feet') {
if (to == 'Square Feet'){
var total = input * 0;
alert ( " ERROR: You are converting to the same unit of measurement! ");
}
if (to == 'Acres'){
var total = input / 43560;
alert (input + " Square Feet equal "+ total + " Acres" );
}
else if (to == 'Poles / Perches / Rods') {
var total = input * 43560;
alert (input + " Square Feet "+ total + " Poles, Perches or Rods" );
}

}


Simple Calculation Script

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

Note that the conversion numbers are not correct. I just haven't done that yet. I also corrected the missing "Else" x 2


Simple Calculation Script

Posted: Tue Jan 03, 2012 3:19 am
by maxkatz

Try commenting out the last two if-blocks and see if the error is in the first one and so on. You can also use Chrome Development Tools or Firebug to see where the problem is.


Simple Calculation Script

Posted: Tue Jan 03, 2012 4:55 am
by wv.wilson75

Got it~ Thanks for the tip. I didn't know I could use firebug.


Simple Calculation Script

Posted: Tue Jan 03, 2012 5:07 am
by maxkatz

Yes, to debug the resulting app in browser.