3
I’d like to know how to do that, when the activeBtn were checked, the ordenadorBanners win the attribute required, I tried the model below but it didn’t work, I would like to know how to do it, and the "why" of having to do it in such a 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>
Put your html code too.
– Allan Andrade
Use the
prop, as follows:$ordenadorBanners.prop('required', true);and after adding therequiredand the user take thecheckof$activeBtnuse the.removeAttr('required');– William Novak
didn’t work :/
– Murilo Melo