Answers for "store object in input value"

1

store object in input value

// encoding
let obj = {
  key1: "foo",
  key2: "bar"
};
document.querySelector('body').insertAdjacentHTML('beforeend', `<input name="sample_input" id="input" value=${encodeURIComponent(JSON.stringify(obj))}>`);

// decoding
JSON.parse(decodeURIComponent(document.querySelector('#input').value));
Posted by: Guest on June-11-2021

Code answers related to "store object in input value"

Browse Popular Code Answers by Language