我终于想出了如何应用j-query来计算联系表格7的单选按钮格式。我遇到的问题是我必须将格式(迷你会话$ 100.00)转换为(100.00迷你会话)以使其计算。我很乐意拥有它(迷你课程$ 100.00)。我也很想复制已选择复制到文本字段的单选按钮的值。
以下是我在Contact form 7 formmat中构建的表单。
<p>Your Name (required)<br />
First Name: [text* RYSFN 20/20 id:RYSFN] Last Name: [text* RYSLN 20/20 id:RYSLN]</p>
<p>Your Email (required)<br />
[email* RYSEM id:RYSEM] </p>
<p>Your Phone Number (required)<br />
[text* RYSPN 15/15 id:RYSPN placeholder "(###) - ### - ####"]</p>
<p>Address (required)<br />
Street Address [text* RYSaddress0 55/50]
Address Line 2 [text* RYSaddress1 55/50]
City [text* RYSaddress2 20/20] State [text* RYSaddress3 4/4] Zip code [text* RYSaddress4 7/7] </p>
<p>Session Date<br />
Session date: [text* RYSSD 20/20 id:RYSSD1 placeholder "Month DD YYYY"]</p>
<p>Session Type<br />
[radio RYSYFS id:RYSYFS class:radio-vertical class:wpcf7-list-item-label "Maternity" "Family" "Newborn" "Baby / Toddler / Child" "Cake Smash" "Milestone"]</p>
<p>Session payment Type<br />
[radio RYSSPT id:RYSSPT class:radio-vertical class:wpcf7-list-item-label "100.00 Mini Session" "Full Session $250.00"]</p>
<p>Extra People<br />
[radio RYSEP id:RYSEP class:radio-vertical class:wpcf7-list-item-label "25.00 1 Person" "2 People 50.00 " "3 People 75.00 " "4 People $100.00 "]
<p>Session Products: <br />
Type of session: [text RYSTS 23/23 id:RYSTS1]
Session Payment: [text RYSSP 8/8 id:RYSSP]
Extra people: [text RYSEP 8/8 id:RYSEP]</p>
<p>Session Payment Amount: <br />
Total Amount: [text RYSTotal 8/8 id:RYSTotal]
Deposit Amount: [text RYSDA 8/8 id:RYSDA]
Balance Amount: [text RYSBA 8/8 id:RYSBA]
Balance Due By: [text RYSBDB 20/20 id:RYSBDB]
<p>I under stand this is a non- refundable, transferrable fee required to reserve an session appointment. I under stand this retainer is non-refundable. <br />
[checkbox* RYSAgree "RYSAgree"] </p>
Breakdown Of Payment:
Total Amount: <span id="total"></span>
Deposit Amount: <span id="deposit"></span>
Balance Amount: <span id="balance"></span>
Balance Due By: [text RYSBA2 20/20 id:RYSBA2]
<p>How would you like to pay the remaining balance (due prior to the session) via:<br />
[radio RYSPB id:RYSPB class:radio-vertical "A PayPal Invoice Apx. 2 weeks before the session." "A PayPal Invoice Apx. day before the session." "I will pay the balance the day of the session With a debit or credit card."]
<p>[submit "Send"]</p>
我的java脚本来计算和复制字段
<script type="text/javascript">
$(document).ready(function() {
$("#RYSSD1").keyup(function() {
$('#RYSBDB').val($(this).val());
$('#RYSBA2').val($(this).val());
});
var inputs = $('input[name="RYSSPT"], input[name="RYSEP"]');
$(inputs).click(function() {
var total = 0;
$(inputs).filter(':checked').each(function() {
total = total + parseInt($(this).val());
})
$('#total').html('$' + total);
$('#deposit').html('$' + (total / 2));
$('#balance').html('$' + (total / 2));
});
});
</script>
我的下一个问题是如何将单选按钮值复制到文本字段以及如何将其添加到脚本中。我有另一个问题,因为当我得到最终剂量的总数0时没有显示。
仍在表单上
这样可以将单选按钮值复制到命名文本字段
$('#1').blur(function() {
$('#3').val($(this).val());
});
如何将单选按钮的值变为命名文本字段。
答案 0 :(得分:0)
用这个替换整个<script>..</script>
位......
<script>
$(document).ready(function() {
$("#RYSSD1").keyup(function() {
$('#RYSBDB').val($(this).val());
$('#RYSBA2').val($(this).val());
});
var inputs = $('input[name="RYSSPT"], input[name="RYSEP"]');
$(inputs).click(function() {
var total = 0;
$(inputs).filter(':checked').each(function() {
var value = ($(this).val()).match(/\$([0-9]*)/)[1];
total = total + parseInt(value);
})
$('#total').html('$' + total);
$('#deposit').html('$' + (total / 2));
$('#balance').html('$' + (total / 2));
$('#RYSTotal').val('$' + total);
$('#RYSDA').val('$' + (total / 2));
$('#RYSBA').val('$' + (total / 2));
});
$('input[name="RYSYFS"]').click(function() {
$(this).blur();
$('#RYSTS1').val($(this).val());
})
$('input[name="RYSSPT"').click(function() {
$(this).blur();
$('#RYSSP').val($(this).val());
})
$('input[name="RYSEP"').click(function() {
$(this).blur();
$('#RYSEP').val($(this).val());
})
});
</script>
答案 1 :(得分:-1)
$ _ GET只检查URL中的查询字符串(/?
之后的URL部分)中的变量。查看表单实际提交的URL。