SOLVED

Re: Field Calculations

Go to solution
Matthew_Libanio
Level 2

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
SanfordWhiteman
Level 10 - Community Moderator

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.

View solution in original post

23 REPLIES 23
SanfordWhiteman
Level 10 - Community Moderator

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.

Matthew_Libanio
Level 2

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!

SanfordWhiteman
Level 10 - Community Moderator

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!