JSFiddle - React, Tailwind, and code Playground
by Sergei Sokolov
HTML
<label>Superclient
<input type="checkbox" id="superclient" checked>
</label>
<br>
<label>Client
<input type="text" name="client">
</label>
<br>
<label>Tourist
<input type="text" name="tourist">
</label>
JavaScript
/**
* для вопроса https://qna.habr.com/q/1024968
* Как проверить checked при загрузке страницы и убрать задержку?
*/
const input = {
client: document.querySelector('input[name=client]'),
tourist: document.querySelector('input[name=tourist]'),
check: document.getElementById('superclient'),
}
const sync = () => {
input.tourist.value = input.client.value;
}
const update = () => {
if (input.check.checked) {
sync();
input.tourist.disabled = true;
} else {
input.tourist.disabled = false;
}
}
input.check.addEventListener('input', update);
input.client.addEventListener('input', update);
update();