[英]Changing Radio Button Label on Wordpress form in jQuery
I have a Wordpress form with a Radio Button input label and value that I need to dynamically generate depending on the input of a another field. 我有一个带有单选按钮输入标签和值的Wordpress表单,我需要根据另一个字段的输入动态生成该标签。
I have no control over how the form is generated (without digging into the plugin, and time is is very much against me, so I just need a quick solution) 我无法控制表单的生成方式(无需深入研究插件,时间非常不利于我,因此我只需要一个快速解决方案)
Wordpress is generating html as follows WordPress的生成HTML如下
<input type="text" name="vfb-22" id="vfb-4-50-22" value="" class="vfb-text vfb-medium number" />
<label for="vfb-4-50-22" class="vfb-desc">Number * 4.50:></label>
<span>
<input type="radio" name="vfb-28" id="vfb-and-then-28-1" value="4.50" class="vfb-radio inline" />
<label for="vfb-and-then-28-1" class="vfb-choice">4.50</label>
</span>
If someone enters a value into field A(vfb-22). 如果有人在字段A(vfb-22)中输入值。 I need jQuery to change the value of the input radio button and the label to A * the current value 我需要jQuery将输入单选按钮的值和标签更改为A *当前值
I currently get all the relevant figures and update another field (vfb-42) correctly as follows 我目前获得了所有相关数字,并按如下所示正确更新了另一个字段(vfb-42)
$('#vfb-monthly-tickets-4-50-each-86').change(function() {
var number=$('input[name=vfb-86]').val();
var multiplier=4.50;
total=number*multiplier;
$('input[name=vfb-42]').val(total);
})
All I'm missing is changing the values of the radio button (vfb-28). 我所缺少的只是更改单选按钮(vfb-28)的值。 I've had a few stabs, with no success to either label of value. 我遇到过几次刺伤,但任何一个价值标签都没有成功。
Grateful for any thoughts 感谢任何想法
If the HTML is always structured this way .. you can try this 如果HTML总是以这种方式构造的..您可以尝试一下
$('.vfb-text').on('change' , function() { // change event of textbox
var $this = $(this); // cache the selector
var count = this.value ; // textbox value
var cost = $this.nextAll('span:first').find('.vfb-choice').text();
// Label text value
total=number * cost ;
$this.next('vfb-desc').text(total); // populate label
$this.nextAll('span:first').find('.vfb-radio').val(total);
// new value of checkbox
});
Admittedly this is just a refactor of your own method, but you could try: 诚然,这只是您自己方法的重构,但是您可以尝试:
$('input[name=vfb-22]').change(function() {
var number=$('input[name=vfb-22]').val();
var current = $('input[name=vfb-28]').val();
total=number*current;
$('input[name=vfb-22]').val(total);
$('.vfb-choice').text(total);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.