WordPress.org

Ready to get started?Download WordPress

Forums

Calculated Fields Form
[resolved] % calculations (7 posts)

  1. nickp87
    Member
    Posted 4 months ago #

    Hey, great plugin.

    Just doing some testing to see i this will work for what i need, i have setup most of my form, and the end result is fine set up as below

    Number1
    Number2
    Result of 1x2
    Cost equals result x10

    Now i need one last calculated field to remove a % of the cost if an option is selected, is this possible and if so how

    Thanks for any help

    https://wordpress.org/plugins/calculated-fields-form/

  2. codepeople
    Member
    Plugin Author

    Posted 4 months ago #

    Hi,

    The process is simple. Suppose your form includes a radio group field, called fieldname1, with two choices, a first choice with value 1, and a second one with value 2. Now suppose your form includes a fieldname2, and you want remove a 20% of fielname2 if the value of fieldname1 is 1, or a 30% if the value of fieldname1 is 2. The equation would be:

    (fieldname1 == 1)?fieldname2*0.8:fieldname2*0.7

    Best regards.

  3. nickp87
    Member
    Posted 4 months ago #

    Hmm, sorry i am clearly not cut out for this as that sounds alien to me :)

    Basically i need the equation to remove 30% (or any other %) from the cost field, would your solution above do that?

    Form is here http://dreammakerbygg.se/?page_id=350 and i need the percentage to come off of the cost estimate field

    Thanks for your help

  4. codepeople
    Member
    Plugin Author

    Posted 4 months ago #

    Hi,

    The URL you sent me display a 404 Error, page not found.

    If you want remove the 30% of a number, the solution is: number*0.7, to remove the 20% is the number*0.8 ....

    The other part of the equation is the ternary operator of JavaScript:

    (condition) ? value1 : value2

    That is interpreted like:

    if condition is true then value1, else value2

    You only should join both concepts in your equation.

    Best regards.

  5. nickp87
    Member
    Posted 4 months ago #

    First of all, thank you very much for you help so far :)

    Using your calculation above, for the 20% off, using the form (fixed now)
    http://dreammakerbygg.se/?page_id=352

    If you input 5 and 2 in the number boxes you get a cost estimate of 420, using a field with the value fieldname10*0.8 should give me 336, but instead gives me 376, also get the wrong cacl for 30%, changed it to remove 50% using *0.5 and that worked fine

  6. codepeople
    Member
    Plugin Author

    Posted 4 months ago #

    Hi,

    If you enter the values 5 and 2, the square meters would be 10, and the cost estimated, that was defined like 47*sq meters, would be 470 and not 420. Finally, the last field, with the equation Estimated Cost * 0.8, would be 470*0.8 = 376

    So your form is working fine, the only way the estimated cost be 420 is modifying the equation associated to the sq meters field.

    Best regards.

  7. nickp87
    Member
    Posted 4 months ago #

    Off to purchase the pro plugin, just for listening to my ramblings, can't believe i thought it was 420 when it shows 470 in the box, must have been to early in the morning for me.

    Thanks again, top notch support :)

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.