V
V
Valera Udav2015-06-10 18:40:30
JavaScript
Valera Udav, 2015-06-10 18:40:30

How to properly store and process data in JS?

I am writing a calculator on the landing page. JS is not very strong in knowledge.

When selecting dropdown items, our final combo should pull data with name, cost value, and text. How to arrange the storage and output of this data? It only comes to mind to sort through all the combinations through the conditions, but in my opinion this is clearly something from the Hindu. It is advisable to give an answer with a small example, thanks!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Ineshin, 2015-06-10
@TARAKANhoy

For example, you have a select:

<select>
    <option value="dsp">ДСП</option>
    <option value="lmdf">ЛМДФ</option>
</select>

Get another object with data:
var type_price = {
    dsp: 10,
    lmdf: 20
};

Now, when changing the value of a select, just read its value. It will be either "dsp" or "lmdf".
To get the price for this type, it will be enough to request it with the following instruction:
var val = select.value; // например "dsp"
var current_price = type_price[val];

And the same for all other selects.

N
Nikita, 2015-06-11
@Rema1ns

don't forget about the chic data() function through which you can store anything you want!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question