Skip to content

Instantly share code, notes, and snippets.

@shankie-codes
Forked from TheHeat/autopopulate.js
Created June 26, 2014 17:22
Show Gist options
  • Save shankie-codes/a6d2285fc568868a17fa to your computer and use it in GitHub Desktop.
Save shankie-codes/a6d2285fc568868a17fa to your computer and use it in GitHub Desktop.
jQuery(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("=");
//decode special characters
var cleanField = decodeURIComponent(field[1]);
//target the field and assign the cleaned up value
$("input[name='" + field[0] + "'], select[name='" + field[0] + "']").val(cleanField);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment