将来自cf7表单的输入添加到相同表单的段落中 [英] Add input from cf7 form to paragraph in same form

查看:68
本文介绍了将来自cf7表单的输入添加到相同表单的段落中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Howard E的帮助下,我可以将下拉字段中的输入显示为占位符.您可以在

With help from Howard E I was able to show the input from a dropdown field into another field as a placeholder. You can find that question here.

Now I would like to show the input of any type of input field into a sentence in a paragraph in that same form.

I tried this code, but unfortunately that didn’t work.

<p>Is [recent-years] is gonna be a good year?</p>

[recent-years] is the name of the cf7 input field. In this case a dropdown field. But also would love to know for textfields and radio/select inputfields.

I guess it’s possible with jQuery, but my knowledge isn’t that great.

Hopefully there’s someone that could help. Thanks!

解决方案

You could try this on the form

<p>Is <span id="recent-years"></span> is gonna be a good year?</p>

And for the jQuery use this:

 jQuery(document).ready(function( $ ){
   $('select[name="recent-years"]').on('change', function(){
       updateParagraph(); 
   });
  updateParagraph();
  
  function updateParagraph(){
    // Assign variable $placeholder to the chosen value
       let $placeholder = $('select[name="recent-years"]').val();
       // replace 'your-field-name' with the cf7 field name
       $('input[name="your-field-name"]').attr('placeholder', $placeholder);
       //New code to also add to the form html
       $('#recent-years').html($placeholder);
  }
});

Tested working, see below

这篇关于将来自cf7表单的输入添加到相同表单的段落中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆