I've come across this nifty little function, to add a hidden input field to an HTML form with JavaScript.
Here's the code:
function addHidden(theForm, key, value) {
// Create a hidden input element, and append it to the form:
var input = document.createElement('input');
input.type = 'hidden';
input.name = key;'name-as-seen-at-the-server';
input.value = value;
theForm.appendChild(input);
}
// Form reference:
var theForm = document.forms['detParameterForm'];
// Add data:
addHidden(theForm, 'key-one', 'value');
addHidden(theForm, 'another', 'meow');
addHidden(theForm, 'foobarz', 'baws');
// Submit the form:
theForm.submit();
What I do not understand is the 'name-as-seen-at-the-server'
in input.name = key;'name-as-seen-at-the-server';
.
What exactly does this set and how is it used?