Get first element by name - Javascript DOM

Javascript examples for DOM:Document getElementsByName

Description

Get first element by name

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Javascript YAML Generator</title> 
   </head> 
   <body> 
      <form class="yamlform" action="index.html" method="post"> 
         <input type="text" name="appname" value="Name"> 
         <button type="submit" onclick="writeAppName()">Submit</button> 
      </form> 
      <script type="text/javascript">
    function writeAppName() {/* ww w.  j a v  a  2 s .  c o  m*/
    var appname = document.getElementsByName("appname")[0].value
      document.write(appname)
    }
    
      </script>  
   </body>
</html>

Related Tutorials