Created
June 10, 2017 14:42
-
-
Save iamtracy/f35407b75de23c5d20d9922d1a8bff69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
document.addEventListener('DOMContentLoaded', Init); | |
function Init() { | |
var oForm = document.forms[0], | |
countryElem = oForm[config.countryUdf], | |
stateElem = oForm[config.stateUdf].parentElement.parentElement, | |
provinceElem = oForm[config.provinceUdf].parentElement.parentElement; | |
provinceElem.style.display = 'none'; | |
stateElem.style.display = 'none'; | |
//create hidden Zift iframe. | |
var iframe = document.createElement('iframe'); | |
iframe.id = 'zift-iframe'; | |
iframe.width = 0; | |
iframe.height = 0; | |
oForm.appendChild(iframe); | |
countryElem.addEventListener('change', dropdown); | |
function dropdown() { | |
if (countryElem.value == 'CANADA') { | |
stateElem.style.display = 'none'; | |
provinceElem.style.display = 'block'; | |
} | |
if (countryElem.value == "UNITED STATES") { | |
stateElem.style.display = 'block'; | |
provinceElem.style.display = 'none'; | |
} else { | |
stateElem.style.display = 'none'; | |
provinceElem.style.display = 'none'; | |
} | |
}; | |
} | |
var g_fnCustomValidationFcn = checkToSend; | |
function checkToSend() { | |
//Inxpo Form and Zift Iframe (Embeds Zift Form), Form Values for both | |
var oForm = document.forms[0], | |
g_cFirstName = oForm.elements["FirstName"].value, | |
g_cLastName = oForm.elements["LastName"].value, | |
g_cEMailAddress = oForm.elements["EMailAddress"].value, | |
g_cCompanyName = oForm.elements["CompanyName"].value, | |
g_cCountry = oForm.elements[config.countryUdf].value, | |
g_cState = oForm.elements[config.stateUdf].value, | |
g_cProvince = oForm.elements[config.provinceUdf].value, | |
g_cCity = oForm.elements["City"].value, | |
g_cPostalCode = oForm.elements["PostalCode"].value, | |
g_cPhone = oForm.elements["Phone"].value, | |
//HTML/Text Block iframe | |
g_oZiftIframe = document.getElementById("zift-iframe"); | |
//Returns PID and PWID value if present, otherwise returns null | |
var g_aPIDVal = getQueryParamVal("PID"), | |
g_aPWIDVal = getQueryParamVal("PWID"); | |
//create hiddden input field to capture PID Values. | |
var injectPID = document.createElement('input'); | |
injectPID.type = 'hidden'; | |
injectPID.name = config.PIDUdf; | |
injectPID.value = g_aPIDVal; | |
oForm.appendChild(injectPID); | |
//create hiddden input field to capture PWID Values. | |
var injectPWID = document.createElement('input'); | |
injectPWID.type = 'hidden'; | |
injectPWID.name = config.PWIDUdf; | |
injectPWID.value = g_aPWIDVal; | |
oForm.appendChild(injectPWID); | |
//create hiddden input field to capture state field. | |
var injectStateProv = document.createElement('input'); | |
injectStateProv.type = 'hidden'; | |
injectStateProv.name = 'State/Province'; | |
injectStateProv.title = "State/Province"; | |
injectStateProv.value = g_cState; | |
oForm.appendChild(injectStateProv); | |
function getQueryParamVal(key) { | |
var cQueryString = window.location.search.substring(1), | |
aParams = cQueryString.split("&"); | |
for (var i = 0; i < aParams.length; i++) { | |
var aKeyValPair = aParams[i].split("="); | |
if (aKeyValPair[0].toUpperCase() === key) { | |
return aKeyValPair[1]; | |
} | |
} | |
return null; | |
}; | |
///Disable Inxpo Email if the PID or PWID key is present within the Query Parameters | |
if (g_aPIDVal !== null || g_aPWIDVal !== null) { | |
oForm.ShowPackageKey.value = config.doNotSendPackageKey; | |
postToZift(); | |
} | |
//HTML/Text block, set hidden iframe src attribute to pass over to zift form hosted on cms -> pages | |
function postToZift() { | |
var cURL = "Server.nxp?LASCmd=AI:4;F:APIUTILS!51004&PageID=36A631B6-3637-46F5-A346-F2BB23559BA2" + | |
"&FirstName=" + g_cFirstName + | |
"&LastName=" + g_cLastName + | |
"&EMailAddress=" + g_cEMailAddress + | |
"&CompanyName=" + g_cCompanyName + | |
"&Country=" + g_cCountry + | |
"&State=" + g_cState + | |
"&Province=" + g_cProvince + | |
"&City=" + g_cCity + | |
"&PostalCode=" + g_cPostalCode + | |
"&Phone=" + g_cPhone + | |
"&PID=" + g_aPIDVal + | |
"&PWID=" + g_aPWIDVal; | |
g_oZiftIframe.src = cURL; | |
}; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment