ashsaraga
4/13/2018 - 6:17 PM

URL Parameter Capture

Will set the value for any input with a name attribute equal to a URL parameter key.

function setParams() {
// Sets the value of any field with a matching name attribute
	var params;
	params = getParams();
	$.each( params, function( key, value ) {
	  var ref;
	  ref = $('input[name="'+key+'"');
	  if (ref.length) {
	  	$(ref).val(value);
	  }
	});
}

function getParams() {
// Gets and decodes all URL Parameters into an array
	var urlParams, url;
	urlParams = {};
	url = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  	urlParams[key] = value;
	});
	return urlParams;
}