In calculator calculate the cost of the product there is a section detail, to calculate the cost of a part you need to know the height, width, number to calculate the square.

The calculator for clarity: https://yadi.sk/i/gYhVXySg3Gkq8n

Tell me how you can implement the calculation of area and insert the number square in the right input. Assuming that the user entered a length first followed by height (when you first enter a number) shows what the size of product in number 1 by default, the area is also immediately changed if you change the data for the calculation after the initial input.

Yet think of each row to hang up the handler on click and on target to hang input event, and then return the value of writing it to the object. Then take the data from the object and count, and handlers for situations when changing the length, height Qty. Something it turns to mush.

The calculator for clarity: https://yadi.sk/i/gYhVXySg3Gkq8n

Tell me how you can implement the calculation of area and insert the number square in the right input. Assuming that the user entered a length first followed by height (when you first enter a number) shows what the size of product in number 1 by default, the area is also immediately changed if you change the data for the calculation after the initial input.

Yet think of each row to hang up the handler on click and on target to hang input event, and then return the value of writing it to the object. Then take the data from the object and count, and handlers for situations when changing the length, height Qty. Something it turns to mush.

asked June 27th 19 at 15:25

1 answer

answered on June 27th 19 at 15:27

All inputy hung listener "change" event and in the handler write that if the variables "length", "width", "number" defined, then calculate the area.

Then when you change the value of any input will be recalculated.

Then when you change the value of any input will be recalculated.

```
var data = {num: 1};
$('#wid, #len, #num').on('change', function (e) {
data[e.target.id] = e.target.value; // the property names of the object match ajtishnikam inputof for simplicity
if (data.wid && data.len && data.num) {
$('.res').html(data.wid * data.len * data.num);
}
});
```

```
<input type="text" id="wid">
<input type="text" id="len">
<input type="text" id="num" value="1">
<div class="res"></div>
```

Find more questions by tags JavaScriptjQuery