Create input HTML element and append to a form - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Create input HTML element and append to a form

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title> Text </title> 
   </head> 
   <body id="tbody"> 
      <script>
    function add(){//  w  w w  .j  av  a 2  s.c o  m
        el = document.getElementById("testform");
        var nf=document.createElement("input");
        nf.type="text";
        el.appendChild(nf);
    }
    
      </script> 
      <p> </p>
      <form id="testform"> 
         <label onclick="add();"> create</label> 
      </form> 
      <p></p>  
   </body>
</html>

Related Tutorials