angular-docs-cn/tools/build/snippets/url_params_to_form.js
Chuck Jazdzewski 43d3a84df3 Revert "refactor: add license header to JS files & format files (#12035)"
This reverts commit 8310c918236c2bc085a0fd4278ee96106c5c2f1a.
2016-10-04 14:06:41 -07:00

20 lines
599 B
JavaScript

// helper script that will read out the url parameters
// and store them in appropriate form fields on the page
(function() {
var regex = /(\w+)=(\w+)/g;
var search = decodeURIComponent(location.search);
while (match = regex.exec(search)) {
var name = match[1];
var value = match[2];
var els = document.querySelectorAll('input[name="'+name+'"]');
var el;
for (var i=0; i<els.length; i++) {
el = els[i];
if (el.type === 'radio' || el.type === 'checkbox') {
el.checked = el.value === value;
} else {
el.value = value;
}
}
}
})();