Created
June 22, 2021 16:05
-
-
Save 8ctopotamus/c4520594ff298ce65e760e8c33d0b453 to your computer and use it in GitHub Desktop.
Autofill fields based on query params
This file contains hidden or 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
window.location.search | |
.replace('?', '') | |
.split('&') | |
.filter(str => !!str) | |
.forEach(str => { | |
const [k, v] = str.split('=') | |
const input = document.querySelector(`[name="${k}"`) | |
input && (input.value = v) | |
}, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment