Q:

how to update the object value on click using javascript

const obj = {'name1':true, 'name2': false, 'name3':true}

I have a onclick function in that I will be getting the name based on this name I need to change the object name value if it is true i need to change to false if it false change to true
Note: this should be happen based on the click only 
my output should be
const obj = {'name1':true, 'name2': true, 'name3':true}

A:

All you need is just to addEventListener to every input, and "duplicate" the current state to the target object. Here is a code example with comments:

const obj = {
  'name1': true,
  'name2': false,
  'name3': true
};

/* Get all inputs */
const inputs = document.querySelectorAll('input');

/* Add "click" listener to every input */
inputs.forEach(input => input.addEventListener('click', () => {
  /* Store current state of clicked input to target object property */
  obj[input.name] = input.checked;
  console.log(obj);
}));
input {
  margin: 12px;
}
<input type="checkbox" name="name1" checked />
<input type="checkbox" name="name2" />
<input type="checkbox" name="name3" checked />

