This is not a duplicate, I've done a lot of research and found nothing that would work for me I need my input field border color to change everytime specific input was detected, but it doesn't work. JS here
Edit: Fixed some stupid mistakes
function zmenitBarvu() {
var inputVal = document.getElementsById("cisla");
if (inputVal.value == "0") {
inputVal.setAttribute( 'style', 'border: 5px solid #f5d442 !important;');
}
if (inputVal.value == "2") {
inputVal.setAttribute( 'style', 'border: 5px solid #f5d442 !important;');
}
else {
inputVal.setAttribute( 'style', 'border: 1px solid #ccc !important;');
}
}
Please help
HTML here
<div class="form">
<form id="cisla">
<input name="cislo1" type="text" class="cisla" placeholder="" id="cislo1" autofocus onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo1.value=cislo1.value.slice(0,2)" /><br>
<input name="cislo2" type="text" class="cisla" placeholder="" id="cislo2" /><br>
<input name="cislo3" type="text" class="cisla" placeholder="" id="cislo3" /><br>
<input name="cislo4" type="text" class="cisla" placeholder="" id="cislo4" /><br>
<input name="cislo5" type="text" class="cisla" placeholder="" id="cislo5" /><br>
<input name="cislo6" type="text" class="cisla" placeholder="" id="cislo6" /><br>
<input name="cislo7" type="text" class="cisla" placeholder="" id="cislo7" /><br>
<input name="cislo8" type="text" class="cisla" placeholder="" id="cislo8" /><br>
<input name="cislo9" type="text" class="cisla" placeholder="" id="cislo9" /><br>
<input name="cislo10" type="text" class="cisla" placeholder="" id="cislo10" /><br>
<input name="cislo11" type="text" class="cisla" placeholder="" id="cislo11" /><br>
<input name="cislo12" type="text" class="cisla" placeholder="" id="cislo12" /><br>
</form>
</div>
var inputVal = document.getElementsByClassName("cisla");What element are you trying to select here? I see no elements withclass="cisla". Also,class=cislo1without quotes is not valid syntax.getElementsByClassNamereturns a list of elements, not a singular element - maybe you meant to iterate through the list insteadcislaI bet that the problem occurs only forinputVal.value == "0", am I wrong?