I'd like to know how to do that, when activeBtn
was checked, ordenadorBanners
got the required
attribute, I tried the template below but it did not work, I'd like to know how to do it, and the " why "having to do it that way.
var $activeBtn = document.getElementById('btn-ativa');
var $ordenadorBanners = document.getElementById('ordem-banner');
if ($activeBtn.checked) {
$ordenadorBanners.required = true;
}
<form>
<fieldset>
<input type="number" name="" min="1" max="10" id="ordem-banner" pattern="">
<label class="switch">
<input type="checkbox" id="btn-ativa">
<div class="slider round"></div>
</label>
</fieldset>
<fieldset>
<input type="submit" name="" value="Cadastrar">
</fieldset>
</form>