html5 - How to get a specific value out of the FormData object -
so have code here
var form = document.getelementbyid("myform"); var formdata = new formdata(form);
form contains 2 textfields, names "title" , "text". before submit form want value of title. tried
console.log(formdata.title); //undefined console.log(formdata[0]); //undefined console.log(formdata.get(title)); //title not defined console.log(formdata.get('title')); // formdata.get not function var j = json.parse(formdata); console.log(" formdata > " + j);// uncaught syntaxerror: unexpected token o var j = json.stringify(formdata); console.log(" formdata > " + j.title); // undefined
how on god's green earth can specific value, based on name of input field ?
thanks
unfortunately, doesn't can in cross-browser friendly way. closest you'll find formdata.getall()
isn't support in ie, edge or safari @ present.
i'd recommend leaving conversion formdata
late possible in code (i.e. send request). libraries form-serialize can if need use/mangle form's value before submitting (alternatively use dom directly).
Comments
Post a Comment