We can create an <input> element with type="hidden" via the document.createElement()
method:
var x = document.createElement("INPUT"); x.setAttribute("type", "hidden");
Click the button to create a Hidden Input Field.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*w w w . j a va 2 s .c om*/ var x = document.createElement("INPUT"); x.setAttribute("type", "hidden"); document.body.appendChild(x); document.getElementById("demo").innerHTML = "The Hidden Input Field was created."; } </script> </body> </html>