We can create a <form> element via the document.createElement()
method:
var x = document.createElement("FORM");
Click the button to create a FORM and an INPUT element.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/* ww w .j a v a 2 s.c o m*/ var x = document.createElement("FORM"); x.setAttribute("id", "myForm"); document.body.appendChild(x); var y = document.createElement("INPUT"); y.setAttribute("type", "text"); y.setAttribute("value", "Set from Javascript"); document.getElementById("myForm").appendChild(y); } </script> </body> </html>