Grab Field Value on Input | Community
Skip to main content
Samantha_Cossum
New Participant
January 29, 2021
Solved

Grab Field Value on Input

  • January 29, 2021
  • 1 reply
  • 3071 views

Hi all,

I'm working on a form that based on what a user enters they want a gauge to show where they are. They would like these gauges to populate on input of the field. Here is the page I am testing on: https://go.schedulinginstitute.com/Hyg-iPad-Test.html 

 

Does anyone know how I can grab the input value from a form field? 

 

Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Use the Forms 2.0 API method Form#getValues() (where Form is the Marketo form object).

 

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
January 29, 2021

Use the Forms 2.0 API method Form#getValues() (where Form is the Marketo form object).

 

 

Samantha_Cossum
New Participant
February 1, 2021

Thanks @sanfordwhiteman! I'm still struggling to get this to work. Can you take a glance at my code and let me know if you see where I'm going wrong? I have this on the page right below the form being loaded.

 

Thanks! 

 

MktoForms2.whenReady(function(form){ var field_val = form.getValues('hygieneHourlyProduction') if( field_val > 300 ) { field_val = 300; $(this).val('$300'); } var percent_formula = 0; var angle_degree = 0; var inc_angle = 0; var percent_base = 100; var range_deg = 0; if( field_val <= 120 ) { percent_base = 120; //120 - 0 range_deg = 45; } else if( field_val >= 121 && field_val <= 189) { percent_base = 68; // 189-121 field_val = field_val - 121; inc_angle = 56; range_deg = 68; } else if( field_val >= 190 && field_val <= 300 ) { percent_base = 110; // 300-190 field_val = field_val - 190; inc_angle = 133; range_deg = 47; } else { field_val = 0; } percent_formula = (field_val * 100) / percent_base; angle_degree = inc_angle + ((range_deg * percent_formula) / 100); degree_txt = 'rotate(' + angle_degree + 'deg)'; $('#average-production-meter .meter-needle').css({ 'transform': degree_txt }) });

 

SanfordWhiteman
New Participant
February 1, 2021

getValues() returns an object:

form.getValues().hygieneHourlyProduction