A
A
Alexey2022-04-12 22:44:59
PHP
Alexey, 2022-04-12 22:44:59

How to dynamically get the cost based on the checked checkbox?

Hello! In general, an extraordinary task arose here, seemingly simple as two times two, but - I sat down in a puddle with it. So, the bottom line is this:

There is a button that, when clicked, opens the bootstrap 4 modal window. This form contains the yoomoney payment form, + 2 radio buttons, by switching which / you can select the payment option:

<form method="POST" action="https://yoomoney.ru/quickpay/confirm.xml">

          <input id="radio-1" class="radio" type="radio" name="radioname" value="radio-block-1" /><label for="radio-1">Купить шаблон</label>
          <input id="radio-2" class="radio" type="radio" name="radioname" value="radio-block-2" /><label for="radio-2">Купить шаблон + помощь по установке</label>
          <div id="radio-block-1" class="radio-blocks" style="display:none">К оплате <strong><?php echo number_format($item['price'], 0, '', ' '); ?></strong> руб.</div>
          <div id="radio-block-2" class="radio-blocks" style="display:none">К оплате <strong><?php echo number_format($item['price'] + 2000, 0, '', ' '); ?></strong> руб.</div>

          <input type="hidden" name="receiver" value="4100117625208247"/>
          <input type="hidden" name="formcomment" value="Покупка"/>
          <input type="hidden" name="short-dest" value="товара"/>
          <input type="hidden" name="label" value="$order_id"/>
          <input type="hidden" name="quickpay-form" value="donate"/>
          <input type="hidden" name="targets" value="<?php echo $item['title']; ?>"/>
          <input type="hidden" name="sum" value="" data-type="number"/>
          <input type="hidden" name="comment" value="Комментарий к платежу"/>
          <input type="hidden" name="need-fio" value="true"/>
          <input type="hidden" name="need-email" value="true"/>
          <input type="hidden" name="need-phone" value="false"/>
          <input type="hidden" name="need-address" value="false"/>
          <input type="submit" value="Купить" class="item-btn btn-fill" style = "width: 100%; margin-top: 15px;" />
          
        </form>


Visually, it looks like this:

6255d59c4e163055051196.jpeg

And now the actual question. How to pass to string
<input type="hidden" name="sum" value="ЗДЕСЬ ЦЕНА" data-type="number"/>
data from radio button 1 or radio button 2, whichever is checked.

I tried both PHP and javaScript - nothing worked. Although the task seems to be trivial. Please kick in the right direction, I will be grateful for the coffin of life)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2022-04-13
@urinov

Thanks everyone, problem solved. I resorted to the help of Ajax.

A
Anton Shamanov, 2022-04-13
@SilenceOfWinter

<input id="radio-1" class="radio" type="radio" name="sum" value="ЗДЕСЬ ЦЕНА">
<input id="radio-2" class="radio" type="radio" name="sum" value="ЗДЕСЬ ЦЕНА 2">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question