CalcBuilder Forum

Option List in Code (Payment calculator)

Usuario moon_1635 2014-07-15 14:05:52

hello,

I am trying to build a payment calculator. The drop down list determines the length and the interest rate is a text box. I can get it to calculate properly for the first item in the dropdown but when something else is selected the length stays the same.

I use an if/elseif statement to the calculation and it appears that when the calculate button is pressed a second time, the coding does not assign which dropdown item is selected.

Hope this makes sense and that someone can offer me some insight.

Moonsoft support 2014-07-15 16:36:18

Hello,
we suggest to double check the values of the options you have set for the combobox. If you have for example a field called 'terms', with these set of pairs (name-value)

Name Value
1 year 1
2 years 2
3 years 3

..you shouldn't need to use if/else conditions:

$result=$terms*10;


Will set result=10 if first value is selected, 20 if second....etc

Hope this helps, if you can't get it working, add a ticket at the helpdesk pasting the code which doesn't calculate the result and we'll take a look looking for any sintax error.

Regards

Usuario moon_1635 2014-07-15 20:00:24

The reason why I am using an if/elseif statement is that I am using the variable to determine the second input into the power function.

In your example I can't pass the 1-year into the second variable location. ($a=pow((1+$c),$1year);) it will not calculate properly.

So I was using the if statement to determine the length and then place a fixed value into the second variable location
$a=pow((1+$c),1);

The other problem I am having is that the new values are not being used in the variables. Let's say my user hits calculate, gives me the answer, then changes the term and hits calculate, this time is uses the first inputs and gives me the same answer.

Please check out the right handle calculator on www.lifemazing.com

Any help would be appreciated.

Thank you

Moonsoft support 2014-07-16 09:39:32

Hello,

First of all, you should change variable name of $1year. Variable should start with a letter or underscore, a number is not allowed as first character in variable. Change it and test it again.

We tested your site and change some fields in form and answers seems to be changing. Please specify what values are 'new' and weĺl test it again.

Regards,

...
List Manager

Build different lists for your site

Buy now!
...
CalcBuilder

Create dynamic calculators

Buy now!