I want to create a JSON object with input variable. I have a 2 input field. when I click button i want to take input values and make a JSON object with that value. I cannot create a JSON object with entered value.
I try that
//getting the value of input as a variable
let id=document.querySelector("#id");
let title=document.querySelector("#title");
first I try the below. it sends a blank value instead of variable string
var vObj= '{"id":'+id.value+',"title":'+title.value+'}'
I also try that to
var vObj = {"id":{},"v_title":{}, "v_category":{}};
vObj.id=id.value;
vObj.title=title.value;
tried that
let asd=id.value;
let bsd=title.value;
var vObj = {id:asd, title:bsd}
it returns a blank value instead of variable value.
i am making a mistake that the trigger button has typo. i couldn't see that. sorry
vObj? The term "JSON object" is a misleading term so it needs clarification.JSON.stringifyto convert it to JSON.