SOLVED

Re: Grab Field Value on Input

Go to solution
Samantha_Cossum
Level 3

Grab Field Value on Input

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!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Grab Field Value on Input

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

 

 

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Grab Field Value on Input

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

 

 

Samantha_Cossum
Level 3

Re: Grab Field Value on Input

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

Re: Grab Field Value on Input

getValues() returns an object:

form.getValues().hygieneHourlyProduction