Add input from cf7 form to paragraph in same form

谁说胖子不能爱 提交于 2021-02-11 13:18:45

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/65765016/add-input-from-cf7-form-to-paragraph-in-same-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!