1

Здравствуйте. Как сделать так, чтобы в amount: где "1799.00" менялось значение из поля sum ? Помогите пожалуйста И еще что бы из поля email добавлялось в CustomerContact

<form class="form1" action="https://money.yandex.ru/eshop.xml" method="post">
  <input required name="shopId" value="00000" type="hidden" />
  <input required name="scid" value="00000" type="hidden" />
  <input name="sum" id="payment-sum" type="text" class="form-control sum" placeholder="Сумма">
  <input class="name" type='text' name="customerNumber" placeholder="Ф.И.О" size="64" />
  <input class="emeil" type="email" placeholder="E-mail" name="custEmail" size="64" />
  <input name="ym_merchant_receipt" value='{"customerContact": "+79250000000","taxSystem": 2,"items": [{"quantity": 1,"price": {"amount": 1799.00},"tax": 1,"text": "Яблоки"}]}' type="hidden" />
</form>

1 ответ 1

1

Не особо разбираюсь в работе с JSON и массивами, но вот такой метод работает.

var obj = {
  "customerContact": "+79250000000",
  "taxSystem": 2,
  "items": [{
    "quantity": 1,
    "price": {
      "amount": 1799.00
    },
    "tax": 1,
    "text": "Яблоки"
  }]
};
var input = document.querySelector('input[name="sum"]');
var output = document.querySelector('input[name="ym_merchant_receipt"]');
output.value = JSON.stringify(obj);
input.addEventListener('change', function(e) { // при необходимости 'change' можно заменить на 'input'
  obj.items[0].price.amount = this.value + '.00';
  output.value = JSON.stringify(obj);
  console.log(JSON.stringify(obj));
});
<form class="form1" action="https://money.yandex.ru/eshop.xml" method="post">
  <input required name="shopId" value="00000" type="hidden" />
  <input required name="scid" value="00000" type="hidden" />
  <input name="sum" id="payment-sum" type="text" class="form-control sum" placeholder="Сумма">
  <input class="name" type='text' name="customerNumber" placeholder="Ф.И.О" size="64" />
  <input class="emeil" type="email" placeholder="E-mail" name="custEmail" size="64" />
  <input name="ym_merchant_receipt" value='' type="hidden" />
</form>

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.