Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to programmatically set or reset checkbox

Purpose: when a particular checkbox is checked or unchecked, the program must change a number of other checkboxes according to programmed rules.

<input type="checkbox" id="chkbox" (change)="onChangeChk($event)">Test Checkbox

  onChangeChk($event) {
    $event.srcElement.value = "on"; // or "off"
  }

The checkbox remains in its original state no matter how the onChangeChk sets it.

Thanks for you help on this. :-)

like image 958
Yogi Bear Avatar asked Dec 07 '22 17:12

Yogi Bear


1 Answers

You can assign the checked property of your input element to true or false.

Like so:

onChangeChk($event) {
    $event.srcElement.checked = true; // or false
}

See also here : https://www.w3schools.com/jsref/prop_checkbox_checked.asp

like image 139
LarsMonty Avatar answered Dec 10 '22 11:12

LarsMonty