Skip to content

Instantly share code, notes, and snippets.

@eightdotthree
Last active August 29, 2015 14:16
Show Gist options
  • Save eightdotthree/f22a3e14d7e71ce5f016 to your computer and use it in GitHub Desktop.
Save eightdotthree/f22a3e14d7e71ce5f016 to your computer and use it in GitHub Desktop.
Populate email field from email param
/*
Function: getUrlParameters
Description: Get the value of URL parameters either from current URL or static URL
Author: Tirumal
URL: www.code-tricks.com
*/
getUrlParameters: function (parameter, staticURL, decode) {
var currLocation = (staticURL.length) ? staticURL : window.location.search,
parArr = currLocation.split('?')[1].split('&'),
returnBool = true;
for (var i = 0; i < parArr.length; i += 1) {
var parr = parArr[i].split('=');
if (parr[0] === parameter) {
returnBool = true;
return (decode) ? decodeURIComponent(parr[1]) : parr[1];
} else {
returnBool = false;
}
}
if (!returnBool) {
return false;
}
}
populateEmailField: function (field) {
var email = this.getUrlParameters('email', '', true);
$(field).val(email);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment