I
I
iSize1ce2014-04-24 19:42:03
JavaScript
iSize1ce, 2014-04-24 19:42:03

How to add prices in JS?

There are multiple select s , choosing different ones so that the number changes. In short, you need to make a price counter for VDS specifications. To choose RAM, SSD, CPU and the price automatically changed. How to do this? I am a complete zero in JS.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
GM2mars, 2014-04-25
@Pavell18RUS

If js is completely zero and you don’t want to understand, then you are on a freelance exchange, and if you want it yourself:
(example on jQuery, but you can still do it on pure js)

function sumSel() {
  var sel=[],
    sum=0;
  sel[1]=$('.sel1').val();
  sel[2]=$('.sel2').val();
  sel[3]=$('.sel3').val();
  for (var key in sel) sum+=parseInt(sel[key]);
  return sum;
}
$(document).on('change', 'select', function() {
  alert(sumSel());
})

Didn't check, but everything seems to be correct. The algorithm is simple: we create a function where we declare variables, an array for selects and a sum. We assign the values ​​of the selects to the array, loop through the array summing up the values, and return the sum.
Below we bind the function to the select event.
This is certainly not a perfect code, but how you can quickly solve your problem.

S
Sergey, 2014-04-24
Protko @Fesor

knockout.js - examples are googled.

Y
Yuri Lobanov, 2014-04-24
@iiil

Order on the freelance exchange. They will write in flight, for a penny.

R
Roman Misyura, 2014-04-25
@MindMinimal

For 200-300 rubles I think they will write. There's really nothing complicated. Everything is simple. You can see the documentation for how to do it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question