Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.addEventListener('keydown', function (event) {
- function modify(input) {
- var output = "Hello World";
- return output;
- }
- // check if enter was pressed
- if (event.keyCode === 13) {
- // prevent key press
- event.preventDefault();
- // Get the text field element
- var text_element = document.getElementById("searchInput");
- // Get text from the element
- var text_input = text_element.value;
- // Modify it
- var text_output = modify(text_input);
- // Writeback Code
- alert(text_output);
- // Set the text_element's value (input text into the field)
- text_element.value = text_output;
- }
- }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement