P
P
Pavel Rozhkov2018-03-21 13:01:17
JavaScript
Pavel Rozhkov, 2018-03-21 13:01:17

How to change the value of the data attribute?

Good day.
The task is the following.
There is a form structure

<div class="checkbox">
        <label><input type="checkbox" id="calculator-yandex" class="calculator-switch" /> Настройка рекламной кампании Яндекс.Директ</label>
        <a class="calculator-question" data-toggle="modal" data-target="#calculator-modal1" href="#">?</a>
      </div>
      <div class="calculator-yandex calculator-hided calculator-option">
        <div class="input-group">
          <span class="input-group-addon">Рекламных кампаний Яндекс.Директ:</span>
          <input class="form-control" type="number" step="1" data-default="1" value="1" min="1" data-cost="7550" />
        </div>
      </div>
      <hr />
      <div class="checkbox">
        <label><input type="checkbox" id="calculator-google" class="calculator-switch" /> Настройка рекламной кампании Google.Adwords</label>
        <a class="calculator-question" data-toggle="modal" data-target="#calculator-modal2" href="#">?</a>
      </div>
      <div class="calculator-google calculator-hided calculator-option">
        <div class="input-group">
          <span class="input-group-addon">Рекламных кампаний Google.Adwords:</span>
          <input class="form-control" type="number" step="1" id="google-total" data-default="1" value="1" min="1" data-cost="7550" />
        </div>
      </div>

data-cost is the cost
The crux of the matter.
If you mark checkboxes separately, then the amount should be displayed 7550, it works all right.
The task is that, if both checkboxes are checked, then Yandex should have the attribute data-cost="7550" and Google should change to data-cost="5000"
The full code is here

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Gorelov, 2018-03-21
@pro100pav

1. option.
I will cut it so as not to write a lot

if(яндекс){
data-cost="7550" //тут целый input
}else{
data-cost="5000" // тут целый input
}

The second option
Just also put a condition.
if this date does not work, you can delete it and then add it again
Well, something like this.
From the most simple.

N
Nikolay, 2018-03-21
@iNickolay

If the checkboxes for #ID1 and #ID2 are checked,
then change the attribute of #ID3 to 5000 ,
otherwise change the attribute of #ID3 to 7550.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question