Advertisement
thetenfold

Untitled

Jul 14th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener('keydown', function (event) {
  2.  
  3.     function modify(input) {
  4.         var output = "Hello World";
  5.         return output;
  6.     }
  7.  
  8.     // check if enter was pressed
  9.     if (event.keyCode === 13) {
  10.  
  11.         // prevent key press
  12.         event.preventDefault();
  13.  
  14.         // Get the text field element
  15.         var text_element = document.getElementById("searchInput");
  16.  
  17.         // Get text from the element
  18.         var text_input = text_element.value;
  19.  
  20.         // Modify it
  21.         var text_output = modify(text_input);  
  22.  
  23.         // Writeback Code
  24.         alert(text_output);
  25.        
  26.         // Set the text_element's value (input text into the field)
  27.         text_element.value = text_output;
  28.     }
  29.  
  30. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement