I decided to replace checkboxes with the ul list and stylize. As a result, I ran into a problem.
How to take a data-attr value from a li list?
And if you select another li, then the corresponding data-attr will be selected.
I tried these options, but for some reason only the first li is taken there and no longer switches:
function costCalculator() { document.getElementById('result').innerHTML = parseInt(document.getElementById('area').value) + 1; } and
function costCalculator() { result.innerHTML = parseInt(area.value) + $('.rooms.active').attr('data-attr'); } \ \ \ \
Sandbox for experiments: https://jsfiddle.net/Mesuti/5kugx8j6/5/
<ul id="room"> <li class="rooms active" data-attr="5">1 ΠΊΠΎΠΌΠ½Π°ΡΠ½Π°Ρ</li> <li class="rooms" data-attr="10">2 ΠΊΠΎΠΌΠ½Π°ΡΠ½Π°Ρ</li> <li class="rooms" data-attr="15">3 ΠΊΠΎΠΌΠ½Π°ΡΠ½Π°Ρ</li> </ul> <input id="area" type="text" value="1" placeholder="ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΠΏΠ»ΠΎΡΠ°Π΄Ρ"> <h2>Π Π΅Π·ΡΠ»ΡΡΠ°Ρ: </h2> <span id="result"></span> // Math Input + Data-attr. INSTEAD XXXXXXX NEED TO TAKE THE VALUE LI. IF CHOOSE ANOTHER LI, THAT VALUE CHANGES.
function costCalculator() { result.innerHTML = parseInt(area.value) + XXXXXXX; }
litag can't have avalue- Air