Skip to content

Instantly share code, notes, and snippets.

@fomigo
Created June 15, 2015 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fomigo/1461f8dfa0172d9f2c0a to your computer and use it in GitHub Desktop.
Save fomigo/1461f8dfa0172d9f2c0a to your computer and use it in GitHub Desktop.
select form input elements from GET params
$(function () {
//grab the entire query string
var query = document.location.search.replace('?', '');
//extract each field/value pair
query = query.split('&');
//run through each pair
for (var i = 0; i < query.length; i++) {
//split up the field/value pair into an array
var field = query[i].split("=");
//target the field and assign its value
$("input[name='" + field[0] + "'], select[name='" + field[0] + "']").val(field[1]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment