javascripthtmlform-data

Accessing FormData Values


I have a FormData object which I create in javascript from an HTML form like so. The FormData object doesn't seem very well documented (it may just be me searching the wrong things!).

var form = new FormData(document.getElementById("form"));

My Question

How do I access the different input values of this FormData object before I send it off? Eg. form.name accesses the value that was entered into the input with the name form.name.


Solution

  • It seems you can't get values of the form element using FormData.

    The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. Its primarily intended for use in sending form data, but can be used independently from forms in order to transmit keyed data. The transmitted data is in the same format that the form's submit() method would use to send the data if the form's encoding type were set to "multipart/form-data".

    However you can achieve it using simple Javascript like this

    var formElements = document.forms['myform'].elements['inputTypeName'].value;