From 18a5425588222413a1d2c041c163b8d45a89d492 Mon Sep 17 00:00:00 2001 From: Cappy Popp <356651+cappypopp@users.noreply.github.com> Date: Wed, 6 Jan 2021 14:54:02 -0500 Subject: [PATCH] adding state to autofill --- LinkedIn - Demo Form Autofill.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/LinkedIn - Demo Form Autofill.html b/LinkedIn - Demo Form Autofill.html index 3092c7d..419df35 100644 --- a/LinkedIn - Demo Form Autofill.html +++ b/LinkedIn - Demo Form Autofill.html @@ -4,6 +4,7 @@ iframeHolderDiv = document.createElement('div'), // so we can style location of button autoFillLocation = document.querySelector("form[id^='mktoForm_']"), // will only find first Marketo form on a page firstRow = document.querySelector('form .mktoFormRow'), + mktoForm, hiddenLinkedInInputs = document.createDocumentFragment(), // since we're creating multiple nodes, just do the add once hiddenInputCreator = function (tagName, onChangeHandler) { var newInput = document.createElement('input'); @@ -262,10 +263,15 @@ mktoCountryInput = document.querySelector("#Country"); // sets the value in the form the user can see if (typeof MktoForms2 !== 'undefined') { - MktoForms2.allForms()[0].setValues({ + mktoForm.setValues({ 'Country': countries[newValue.toUpperCase()]}); } }); + hiddenInputCreator('state', function(newValue){ + mktoForm.setValues({ + 'State': newValue.toUpperCase(); + }); + }); /*['email', 'country'].forEach(function(inputField){ var newInput = document.createElement("input"); @@ -307,6 +313,7 @@ // need the id of the form so we can hook up autofill // doing this way will work on any Marketo form fillScript.setAttribute('data-form', 'mktoForm_' + form.getId()); + mktoForm = form; form.onSubmit(function (form) { console.log('onSubmit'); console.log(form.vals());