Call eval function to access DOM property - Javascript Language Basics

Javascript examples for Language Basics:eval

Description

Call eval function to access DOM property

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <input type="text" onkeyup="myFunction(this.value)"> 
      <p id="message"></p> 
      <script type="text/javascript">
function myFunction(propName) {/* w ww  .j  a  v a2s .  c om*/
  var p = document.getElementById("message");
  try {
    p.innerHTML = eval(propName);
  } catch(e) {
    p.innerHTML = "invalid";
  }
}

      </script>  
   </body>
</html>

Related Tutorials