Skip to content

Instantly share code, notes, and snippets.

@gchristofferson
Last active February 6, 2019 18:37
Show Gist options
  • Save gchristofferson/de61bfec17a2b433565dafdfd92a7b49 to your computer and use it in GitHub Desktop.
Save gchristofferson/de61bfec17a2b433565dafdfd92a7b49 to your computer and use it in GitHub Desktop.
Get users search input and add it to form action
// Get users search input and add it to form action
$('#js-search-input').keypress(function (e) {
let key = e.which;
// if the key is the enter key code
if(key === 13) {
const userInput = $('#js-search-input').val();
console.log("user input: " + userInput);
let actionStr = "/inquiries/search/" + userInput;
console.log("actionStr = " + actionStr);
actionStr = actionStr.replace('?', '');
// window.location.replace(actionStr);
document.getElementById('js-search-form').action = actionStr;
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment