A
A
Adel Khalitov2019-02-12 18:30:53
JavaScript
Adel Khalitov, 2019-02-12 18:30:53

How to manage multiple house elements?

Good afternoon everyone, a theoretical question.
Here, for example, I implement a calculator (Conditionally which counts 2 + 2) It takes the operation from one input and when it does not matter what action, let change do the calculations.
I made up, described some class that does it.
What I want to do next:
~When I click on the (conditionally) "Add Calculator" button, I should have the same calculator on the page and do the same calculations. I need to do this endlessly, and, on top of all this, I should have another class that will sum up the results of all calculators (This is a very conditional example, but this is exactly the problem I am currently solving for practice).
I need to understand on elementary things how to implement this in native js.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-02-12
@SaveLolliPoP

Have you heard of arrays? What prevents you from creating inputs like this:

<input name="myCalc[0][firstValue]" >
<input name="myCalc[0][secondValue]" >
<input name="myCalc[1][firstValue]" >
<input name="myCalc[1][secondValue]" >

Implement 1 class that will calculate both the subtotal and the grand total by manipulating an array or rather an object based on it. Catching change and changing the data in this object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question