In key down event, add content to div according to text input field value - Javascript DOM

Javascript examples for DOM:Key Event

Description

In key down event, add content to div according to text input field value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  www. ja v a 2  s. c  om
document.getElementById("setter").addEventListener('keydown', function(e){
    if(e.keyCode === 13) {
      var from = this.value;
      x = document.getElementById("mything");
      x.innerHTML = from;
    }
})
    }

      </script> 
   </head> 
   <body> 
      <input id="setter"> 
      <div id="mything"></div>  
   </body>
</html>

Related Tutorials