Created
June 15, 2015 13:53
-
-
Save fomigo/1461f8dfa0172d9f2c0a to your computer and use it in GitHub Desktop.
select form input elements from GET params
This file contains 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 () { | |
//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