crazy4groovy
4/10/2013 - 8:56 PM

Populate input values with names found in the url query string.

Populate input values with names found in the url query string.

(function($) {
    $.queryInputs = function(enforceFormScope) {
        var url_params = location.search.toString().slice(1).split('&');
        var pre = '';
        if (enforceFormScope) {
            pre = 'form ';
        }
        for (var i = 0; i < url_params.length; i++) {
            var k = url_params[i].split('=')[0],
                v = url_params[i].split('=')[1];
            $(pre+'input[name="'+k+'"]').val(v);
        }
        return url_params;
    }
})(jQuery);