I have two code "snippets" that I would like to combine but I don't really know how to.
I've managed to make HTML form input into an JSON object. See codepen here.
When I click the "Add note" btn I want to grab the input values -> make them to an object -> POST them to my api object array. Image and code example below:
// CREATE NEW NOTES
var btn = document.getElementById('btn');
btn.addEventListener("click", function() {
var request = new XMLHttpRequest();
request.open('POST', 'https://timesheet-1172.appspot.com/af25fa69/notes');
request.setRequestHeader('Content-Type', 'application/json');
request.onload = function () {
// When I click the "Add note" btn I want to grab the input values -> make them to an object -> POST them to my api object array.
// Like
// var body = {
// 'title': form.title.value,
// 'description': form.description.value
// }
};
request.send(JSON.stringify(body));
});
This is the current code that I have which let's me send an already set variable with object properties. See image below:
However my question is regarding how i can combine these tho examples so I can make dynamic inputs -> convert them to a JSON object -> Insert them in the api object array.
Feel free to correct me if you think that i'm on the wrong path or if you think have a solution!
If you have any questions or need clarification don't hesitate to ask!
Thanks beforehand!
// E

