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