A
A
Artem Ponomarev2018-02-19 23:39:27
css
Artem Ponomarev, 2018-02-19 23:39:27

How to fix calculator in JS?

Hello everyone, dear friends! I turn to you with a request for help. I have a calculator on the site, the view is as follows:

function changeText0(){
     var res = 1;
     var a = parseFloat(document.getElementById('a').value);
     var b = parseFloat(document.getElementById('b').value);
     var c = parseFloat(document.getElementById('c').value);
     var d = parseFloat(document.getElementById('d').value);

     if (document.getElementById('c').checked) 
        res = a + b + c;
     if (document.getElementById('d').checked) 
        res = a + b + d;
                                                  
     document.getElementById('res').innerHTML = res;
}

and HTML markup:
<form onsubmit="return false;" oninput="changeText0()">
   <label>Площадь здания</label><br>
   <input id="a" type="number" min="0"><br>

   <label>Количество помещений в здании</label><br>
   <input id="b" type="number" min="0"><br>

   <label>Тип потолка:</label><br>
   <input id="c" type="radio" name="potolok" value="100"> Армстронг<Br>
   <input id="d" type="radio" name="potolok" value="200"> Другой<Br>

   <label>Цена:</label><br>
   <output id="res">0</output>
</form>

When changing numbers, the result is immediately displayed. But if you choose a radio, the result does not change depending on the radio itself. You need to change the number again to get the result. I need for example: we have the numbers 10 and 10. We change the radio, and the result immediately appears without changing the numbers.
I can't figure out what's the problem? Maybe someone knows the solution?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BB 8, 2018-02-19
@goldmayor

strange, but in Firefox everything changes:
here1
here2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question