Ответ 1
document.forms
object - это совокупность всех элементов <form>
на странице. Он имеет числовые индексы и названные элементы. Именованные элементы соответствуют атрибуту name
для каждого <form>
.
var theForm = document.forms['detParameterForm'];
Чтобы упростить добавление данных, вы можете создать функцию, которая добавляет данные для данной формы.
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; // 'the key/name of the attribute/field that is sent to 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();