L
L
ligisayan2015-06-22 17:59:39
css
ligisayan, 2015-06-22 17:59:39

How to convert the counter to the desired form?

Hello. I have a counter that counts the quantity and amount of a particular product. The span with the quantity class stores the quantity and the amount in the form "13 x 70 rubles." input c type="number" should take the value of quantity, i.e. digit 13. input c type="button" increase/decrease the value of the input c type="number" variable, which should also be reflected in quantity, and the amount in amount should be overwritten in full, i.e. sum = 13 * 70 = 910 rubles Complexity in converting strings to values ​​​​and in automatic tracking of changes with the exchange of information between selectors. In the code I wrote the meaning of what I want to get. Can you help with the transformation?

<span class="quantity">13 × <span class="amount">70&nbsp;руб.</span></span>
<div class="quantity buttons_added">
  <input type="number" step="1" min="1" max="27" id="num_count" name="quantity" value="1" title="Кол." class="input-text qty text" size="4">
  <input type="button" value="+1" id="button_plus" class="plus">
  <input type="button" value="-1" id="button_minus" class="minus">
</div>

var quantity = $(".quantity").text();
$(".input-text.qty.text").val(quantity);
var amount = $(".amount").text();
var total = amount * quantity;
$(".quantity").text() = $(".input-text.qty.text").val(quantity);
$(".amount").text() = total;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2015-06-22
@Stalker_RED

You have in .quantitynot 13 but 13 × <span class="amount">70&nbsp;руб.</span>
Move it into a separate element, for example. And most likely you will need parseInt().
And in general, tin, of course.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question