Skip to content

Instantly share code, notes, and snippets.

@freegenie
Created March 26, 2020 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freegenie/17addc0be3dfd1fde6e9d5491a4d88c3 to your computer and use it in GitHub Desktop.
Save freegenie/17addc0be3dfd1fde6e9d5491a4d88c3 to your computer and use it in GitHub Desktop.
var mapping = {
'last_lp_brand' : 'SEAT'
} ;
window.addEventListener('message', event => {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
console.log(">> Form is ready!");
Object.keys( mapping).forEach(function(key) {
var input = 'input[name=' + key + ']';
if ( jQuery( input ).length === 0 ) {
console.warning( ' field ' + input + ' was not found !!' );
}
jQuery( input ).first().val( mapping[key] );
console.log( '>> form field ' + key + ' set to value ' + mapping[key] );
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment