Create a Form Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form


You can create a <form> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">create a FORM and an INPUT element</button>

function myFunction() {//from   w  w w  .j av a  2s. co  m
    var x = document.createElement("FORM");
    x.setAttribute("id", "myForm");

    var y = document.createElement("INPUT");
    y.setAttribute("type", "text");
    y.setAttribute("value", "Donald");


Related Tutorials