SOLVED

# Field Calculations

Go to solution
Level 2

## Field Calculations

Is it possible for a customer to enter data into one or two fields and have a third field calculate the value and immediately display for the customer to see?

For example:

Lot Size: 1000 Sq. Ft.

Salt melt area: 1 bag/500sq. ft

Bags of Salt  Needed: 2 bags

So the calculated value will be the Bags of Salt, but the first entry is all that is needed.  The Salt Melt area will be a default hidden value stored in the field.

Thanks everyone!

1 ACCEPTED SOLUTION

Accepted Solutions
Level 10 - Community Moderator

## Re: Field Calculations

JS has all the built-in math functions you need.

Here's a naive implementation of what you're talking about: MktoForms2 :: Client Calc

Ignoring the confusing field names (I do this so I don't have to clutter my prod instance with unused fields) the approach is that you have the rate stored in a hidden field (like you said) and then you prompt the user for the lot size.  Only when they submit the lot size, you actually multiply the lot size by the hidden rate before submitting the form to the Marketo db.

You'd probably find it more visually appealing to have a second hidden field that stores the lot size * rate.  Then you don't have to "magically" update the lot size field while the user is watching.  Or you could just hide the form while you're submitting, same difference so they don't see that.  Anyway, this is just as a quick-and-dirty demo of how you can massage field values any way you want before posting to Marketo.

23 REPLIES 23
Level 10

## Re: Field Calculations

If you're doing real-time calculations with the point of showing a prospect, I'd do that with JavaScript, and then send the calculated value to Marketo as a field value. Those kinds of calculations will be very easy to do with some simple JavaScript coding.

Marketo can do linear math (adding and subtracting) but anything more complex than that is easier to do outside of Marketo.

Cheers,

Edward Unthank | Founder, Etumos

Level 2

## Re: Field Calculations

This sounds interesting.  Any example you can provide as to how to pass that data value to Marketo.  What JS method would one use?

Thanks so much!

Level 10 - Community Moderator

## Re: Field Calculations

JS has all the built-in math functions you need.

Here's a naive implementation of what you're talking about: MktoForms2 :: Client Calc

Ignoring the confusing field names (I do this so I don't have to clutter my prod instance with unused fields) the approach is that you have the rate stored in a hidden field (like you said) and then you prompt the user for the lot size.  Only when they submit the lot size, you actually multiply the lot size by the hidden rate before submitting the form to the Marketo db.

You'd probably find it more visually appealing to have a second hidden field that stores the lot size * rate.  Then you don't have to "magically" update the lot size field while the user is watching.  Or you could just hide the form while you're submitting, same difference so they don't see that.  Anyway, this is just as a quick-and-dirty demo of how you can massage field values any way you want before posting to Marketo.

Level 2

## Re: Field Calculations

This sounds exactly right, but for some reason the page does not load entirely.  But you solutions sounds exactly right.  Would be cool to see it in action if you could!

Level 10 - Community Moderator

## Re: Field Calculations

Where doesn't it load? It even works on my Blackberry...

Level 2

## Re: Field Calculations

Hi Sanford, so I can reduce this even further and make it simpler.  Your help or anybody is appreciated.

Landing Page 1 will ask customer to fill in Lot Size

Lotsize = Customer Input

Numbags = Lotsize/500 (no decimal places)

When they press SUBMIT, the Numbags field will populate based on the calculation above, but customer does not see that.

On the final landing page it will say:

Thank you {{lead.firstname}}, you will need {{lead.NumBags}} for this winter season.  Shop Now.

Any help is appreciated!  Thank you so much everyone!

Level 10 - Community Moderator

## Re: Field Calculations

Can you still not see my demo code?

It should be easy to adapt it so that the user sees the NumBags on the next page. The onSuccess function always gets the two args (postedValues,followUpURL).  So you can read directly out of postedValues.NumBags.

Level 2

## Re: Field Calculations

Hi Sanford, as I said, my js coding skills are okay.  If it is built, I know what to do, but to start from scratch... well...

If you like, I am more than happy to pay for the effort, as long as it is reasonable! Hahaha!  PM me if you wish!  Oh and yes I can see your code now!

Level 10 - Community Moderator

## Re: Field Calculations

Follow me back and we can PM.  I'm sure we can keep it pro bono... but this thread is just getting in the way!