Create a hidden field in JavaScript

javascript

Solution

var input = document.createElement("input");

input.setAttribute("type", "hidden");

input.setAttribute("name", "name_you_want");

input.setAttribute("value", "value_you_want");

//append to form element that you want .
document.getElementById("chells").appendChild(input);

Problem

How do you create a hidden field in JavaScript into a particular form ? ``` <html> <head> <script type="text/javascript"> var a =10; function test() { if (a ==10) { // ... Here i need to create some hidden field for form named = chells } } </script> </head> <body > <form id="chells" name="formsdsd"> <INPUT TYPE=BUTTON OnClick="test();"> </form> </body> </html> ```

Original source