【问题标题】:Value of radio button copy to text field单选按钮的值复制到文本字段
【发布时间】:2014-12-21 06:36:36
【问题描述】:

我终于想出了如何应用 j-query 来计算联系表单 7 的单选按钮格式。我遇到的问题是我必须将格式(迷你会话 $100.00)反转为(100.00 迷你会话)才能计算。我很想拥有它(迷你会议 $100.00)。我也很想复制已选择复制到文本字段的单选按钮的值。

这是我的表单,它是用 Contact form 7 格式构建的。

    <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());
});

如何将单选按钮的值设置为命名文本字段。

【问题讨论】:

  • 我的表单电子邮件,我唯一的事情是联系表单 7 代码中的内容括号我没有得到用 HTML 编写的内容。我不知道如何制作,所以我可以获取 html 中的内容,然后将选择的内容发送给我。
  • 所有输入都不能不使用 CF7。
  • 你知道我怎样才能把它变成 cf7 输入,这样我就可以计算它们了。
  • contactform7.com/checkboxes-radio-buttons-and-menus ... 然后修改jQuery,定位到CF7输出的html

标签: javascript email get contact-form-7


【解决方案1】:

用这个替换你的整个 &lt;script&gt;..&lt;/script&gt; 位...

<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>

【讨论】:

  • 好的,只是在错误的位置修复了错误的 ID,谢谢谢谢谢谢。 :)
  • 好的,我如何添加另外两个其他字段来复制(会话付款)和(额外的人)我只是复制你为收音机所拥有的并将其放在你所拥有的之下吗?
  • 差不多,是的。我为此再次更新了代码
  • 好的有一个问题,如果我先有金额而不是名称,然后金额为 100.00 迷你而不是迷你 100.00 美元,并且我无法在结尾处得到零,为什么剂量只能获得总金额总计,如果有 $ 符号,则不会总计
  • 这是因为代码使用了parseInt,它试图将文本转换为数字(因此它可以将它们相加)但只有当文本以数字开头时才能这样做。如果你想要最后的数字,我也可以用不同的方式来实现吗?
【解决方案2】:

$_GET 仅检查 URL 中的查询字符串(/? 之后的 URL 部分)中的变量。查看表单实际提交到的 URL。

【讨论】:

  • 你能再解释一下吗?我不明白你在说什么。这对我来说是全新的
  • 我发现我改变了我的问题,因为我不能再提出任何问题了。
猜你喜欢
  • 2018-01-04
  • 1970-01-01
  • 2019-01-16
  • 2018-12-07
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 2012-12-17
  • 1970-01-01
相关资源
最近更新 更多