F
F
FallenBlick2014-11-11 04:15:32
JavaScript
FallenBlick, 2014-11-11 04:15:32

How to calculate the amount for the number of products in javascript?

Good day!
There is such a code

<td>
<input type="text" name="count-item" id="count" value="1">
 </td>
<span id="cost">52.5</span>
<span id="result"></span>

tell me the code so that when the number in Input (Count) changes, it takes the value and multiplies it by span (Cost) and displays the result in span (result)
Thank you!
PS If you can, then still advise a good book on javascript. I have mastered PHP HTML CSS and actively work, but I am practically not familiar with JS.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
YemSalat, 2014-11-11
@YemSalat

var cost = document.getElementById('cost');
var count = document.getElementById('count');
var result = document.getElementById('result');

count.addEventListener('change', function() {
  result.textContent = parseInt(count.value, 10) * parseFloat(cost.textContent);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question