Skip to content

Instantly share code, notes, and snippets.

@loraxx753
Created February 7, 2019 16:02
Show Gist options
  • Save loraxx753/150dcce59dae3e428110164399cc6367 to your computer and use it in GitHub Desktop.
Save loraxx753/150dcce59dae3e428110164399cc6367 to your computer and use it in GitHub Desktop.
export const getInput = () => new Promise((resolve, reject) => {
document.querySelector('form').addEventListener('submit', function listener(e) {
e.preventDefault()
const inputString = e.target.querySelector('input[type=text]').value
resolve(inputString)
e.target.removeEventListener('submit', listener)
})
})
/* USAGE
const credentials = await getInput()
const [ username, password ] = credentials.split('|').map(s => s.trim())
console.log(credentials)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment