我想根据单选按钮的选择,以百分比和卢比计算折扣


I Want to calculate discount in percentage and rupees based on radio button selection

我有两个单选按钮,第一个是百分比折扣,第二个是卢比折扣。根据单选按钮的选择,我想显示结果。请为我提供相同的功能或建议其他方法。前端是php语言。

试试这个

Amount : <input type="text" id="amount" value="100" />
Discount : <input type="text" id="discount" value="10" />
Balance : <input type="text" id="balance" value="90" />
Discount in Percentage : <input type="radio" class="discount-type" value="1" checked name="dc" />
Discount in Amount : <input type="radio" class="discount-type" value="2" name="dc"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function () {
     var total, discount;
     $('input[type=radio][name=dc]').change(function() {
        total = $('#amount').val();
        discount = $('#discount').val();
        if (this.value == '1') {
            $('#balance').val(total-((discount/100)*total));
        }
        if (this.value == '2') {
            $('#balance').val(total-discount);
        }
    });
});
</script>