Created
April 13, 2018 18:17
-
-
Save ashsaraga/e81627862994e3ba1c334681e94c823b to your computer and use it in GitHub Desktop.
Will set the value for any input with a name attribute equal to a URL parameter key.
This file contains hidden or 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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment