I am trying to return a price after specific discount, and have checked with the part of Js on w3schools.com, in my case, the formula is not difficult, it looks like the z=x*0.85, but in this example below, where I can not set an undefined custom numeric field as a multiplier.
my questions are:
1. if I set a single line numeric field, that id="original-price", and display the price after 15% discount as id="net-price", How should I do by the shortcode below? just add that id="original-price" in to "[ ]"
2. if I want to restore the value after calculated, and display this on the post, how do I create that custom field and use the value as the value of field?
Thank you so much!
[cred_field field='original-price' post='room' value='' urlparam='' class='form-control' id='monthly-rate' output='bootstrap']
<p id="net-price"></p>
<script>
var z = 20* 0.85;
document.getElementById("net-price").innerHTML = z;
</script>
Hello,
It is a custom codes problem,
Q1) How should I do by the shortcode below? just add that id="original-price" in to "[ ]"
I need detail steps to duplicate the same problem, how do you stup the custom field "original-price"? how and where do you want to add the ID?
You can post the question in Chinese and share the live problem URL.
Q2) Same as above, I need details, where can I see the value? what and how do you want to restore the value?
And I have enabled the private detail box, please provide detail steps to see the problems you mentioned above. thanks
Q1) [cred_field field='discount' value='' urlparam='' class='form-control' output='bootstrap'] 如果我想指定一个值,而不是允许用户在前端提交的话, 我是不是可以填 value='0.8' 然后我隐藏此字段?
是的,你只需要将默认值“value”设置为0.8,例如:
[cred_field field='discount' value='0.8' urlparam='' class='form-control' output='bootstrap']
然后再隐藏此字段
Q2) 计算公式为, Monthly rate * discount = Net rate, 结果取整数。
我在这个表单内添加了JS代码如下:
jQuery( document ).ready(function($) {
$('input[name="wpcf-monthly-rate"]').change(function(e){
var monthly_rate = $('input[name="wpcf-monthly-rate"]').val();
var discount = $('input[name="wpcf-discount"]').val();
var net_rate = Math.round(monthly_rate * discount);
$('input[name="wpcf-net-rate"]').val(net_rate)
});
});
供你参考
Q3) 应该与Q2是同一个问题,我已经在你的网站上测试过,上面的代码工作正常,注意这只是一个例子供你参考
Q4和Q5 这两个是新问题,请开新帖,方便其他用户参考,谢谢!
第四和第五不是问题,只是帮助我说明情况,非常感谢 测试过 很不错~~~ 谢谢