How to add hidden fields to form and submit with Javascript

In HTML Code:

<form action='myScript.php' method='get' name='myForm'>
</form>

Javascript code:

var form = document.forms['myForm'];
// form.action = 'put your url here';
var na = document.createElement("input");
na.type = "hidden";
na.name = "name";
na.value = "Bob The Builder";
form.appendChild(na);

form.submit();

 

You may also like...

Leave a Reply