Your question was:
...all the values of every form element...
but your selector was only for input elements in one particular form. Presuming that you actually wanted the values of all the controls in a form, then the following POJS may suit:
function getFormValues(formId) {
var data = {};
var form = document.getElementById(formId);
if (form) {
var control, controls = form.elements;
if (controls) {
var i = controls.length;
while (i--) {
control = controls[i];
data[control.id] = control.value;
}
}
}
return data;
}
Presuming that every control has an ID, which is not a requirement. If some controls don't have an id, you might want to use the name property instead, so:
data[control.id || control.name] = control.value;
In some cases, your controls may not have an id or a name (e.g. controls that are needed for the form but whose values are not to be submitted, such as submit and reset buttons) so:
var idOrName = control.id || control.name;
if (idOrName) {
data[idOrName] = control.value;
}
You may also need to deal with controls having the same name, since the value of whichever one is accessed last will replace the value of previous same-named controls.