Re: Code Assistance - Conditional Form Field display

Anonymous
Not applicable

Code Assistance - Conditional Form Field display

Hi Gang-
I'd like to add a piece of code to my US business unit pages to show Canadian visitors our opt-in button to ensure compliance with the new candian anti-spam regulations. It would be much faster to merely query on country & then when Canada display the opt-in, than to create a 2nd set of everything for only canadian viewers. As we market to both countries in English we consider them a single business unit.
 

Does anyone have any recommendations on this? Perhaps Erik H has already written a help doc. He has already written about GeoIP lookup,
 

<**** type="text/javascript" language="Javascript">
  // convert the JSON => Object
  var geoip =  eval("(" + mktoPreFillFields + ")");
  
  // pull out the inferred fields for use later
  var geo_country_code  = geoip.InferredCountry;
</*****>

jQuery(document).ready(function($){
  // allow in-domain javascript access
  // see http://www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/
  document.domain='hollebone.ca';

  // use the marketo field to populate the form
  $('#Country option[value='+geo_country_code+']').attr('selected', 'selected');
  $('#State option[value='+geo_country_region +']').attr('selected', 'selected');
})There are the two bits of code from his page... I'm currently replacing the field label to include a link to my privacy policy..

<**** type="text/javascript">
$('#RequestedNewsletter').parent().children('label').html('I accept the website <a target="_blank" title="Our Terms and Conditions" href="http"//example.com/tancd.html">terms and conditions</a>.');
</***** >

How do I put these two pieces of code together to only show the field #RequestedNewsletter when geoip.InferredCountry = Canada.

 

Tags (1)
1 REPLY 1
Anonymous
Not applicable

Re: Code Assistance - Conditional Form Field display

I would recommend caution relying on GeoIP. Users on VPN may not reflect the actual inferred country.
 
http://www.geoiptool.com displays my location as US when I am on VPN.
 
A safer approach to mitigate this sort of false positive is forcing users to select the country and taking action when specific values are selected. 
 
The script in the article "Dynamic State and Province for US and Canada in forms" can be reduced to evaluate Canada only and then present the checkbox.