vendredi 14 mai 2021

how do we push a checkbox to an array while checkbox is by default checked in react js?

the checkbox by default checked if this checkbox is by default checked then it should be automatically pushed into addtess_type array.

handleInputChangeDom = (event) => {
    const target = event.target;
    var value = target.value;
    const Address_type = this.state.Address_type;
    
    if (event.target.checked) {
      Address_type.push(event.target.value);
    } else {
      let index = Address_type.indexOf(event.target.value);
      Address_type.splice(index, 1);
    }

    this.setState({
      Address_type: Address_type,

    });
  };



Aucun commentaire:

Enregistrer un commentaire