Sep 19, 2561 BE
Search around internet, look at the example below.
Oct 23, 2565 BE
On the first input, the user taps the "Check" button, changes focus to the next input and then clicks the .
const checkbox = document.querySelector('input');
const subject = new BehaviorSubject(false);
checkbox.onfocus = e => {
if (!checkbox.checked) {
subject.next(true);
}
};
checkbox.onchange = e => {
if (e.target.checked) {
subject.next(true);
} else {
subject.next(false);
}
};
const alertMessage = (text) => {
const alert = document.querySelector('.alert');
alert.textContent = text;
alert.classList.add('alert-success');
};
subject.subscribe((isChecked) => alertMessage('The checkbox is now'+ isChecked));
Checked Checkboxes Example ac619d1d87
Related links:
Comments