Clear Pre-populated form field only for certain values | Community
Skip to main content
February 19, 2015
Solved

Clear Pre-populated form field only for certain values

  • February 19, 2015
  • 3 replies
  • 1297 views
We have some forms that only collect email address. All leads are automatically pushed to SFDC and since Last Name/Company are required, they are automatically set to "NEEDS INFO". When a lead fills in the next form, they are now seeing the ugly "NEEDS INFO" in the pre-populated fields.

I do not want to turn off pre-population becasue in most cases the values are correct. However, I would like to be able to clear the field if it contains "NEEDS INFO".

I tried this Javascript but it isn't working. Any ideas why or how I can do this? Thanks so much for your help!

<script type="text/javascript" src="/js/public/jquery-latest.min.js"></script>
<script type="text/javascript">
    // set no conflict mode for jquery
  var $jQ = jQuery.noConflict();

  $jQ(document).ready(function(){
  var CompanyField = $jQ("#Company");
  var LastNameField = $jQ("#LastName");
  if (CompanyField == "NEEDS INFO") 
     {
      $jQ('#Company').attr('value','')
     }
  if (LastNameField == "NEEDS INFO") 
     {
      $jQ('#LastName').attr('value','')
     }
  });
</script>
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
Thanks, Kenny, you were absolutely right. I was using the old 1.0 forms jquery on a 2.0 form.

In case anyone is interested, here's the 2.0 version of the code:

<script>
  MktoForms2.whenReady(function (form){
    //Put your code that uses the form object here.
    var vals = form.vals();
     if(vals.LastName == "NEEDS INFO"){
      form.vals({"LastName":""});
    }
    if(vals.Company == "NEEDS INFO"){
      form.vals({"Company":""});
    }
  });
</script>

Regards,
Sheila

3 replies

Josh_Hill13
Level 10
February 19, 2015
I'd check with a developer or developers.marketo.com.

success@perkuto.com can help in a pinch.
Kenny_Elkington
Adobe Employee
Adobe Employee
February 19, 2015
Hi Sheila,

Assuming you're using a Forms 2.0 form, you should use the forms 2.0 API: http://developers.marketo.com/documentation/websites/forms-2-0/  the .vals() and .setValues() methods will allow you to do this.
Accepted solution
February 20, 2015
Thanks, Kenny, you were absolutely right. I was using the old 1.0 forms jquery on a 2.0 form.

In case anyone is interested, here's the 2.0 version of the code:

<script>
  MktoForms2.whenReady(function (form){
    //Put your code that uses the form object here.
    var vals = form.vals();
     if(vals.LastName == "NEEDS INFO"){
      form.vals({"LastName":""});
    }
    if(vals.Company == "NEEDS INFO"){
      form.vals({"Company":""});
    }
  });
</script>

Regards,
Sheila