admin管理员组文章数量:1313188
I am converting a static theme to a wp-theme and I am working on forms with wpcf7 plugin. I am wondering how can I write this code with wpcf7 text tag.
<input type="text" name="name" id="name" value="" onchange="this.setAttribute('value',this.value);" required/>
All what I could do is this
[text* name id:name]
my question is how can I add onchange to this text input ?
I am converting a static theme to a wp-theme and I am working on forms with wpcf7 plugin. I am wondering how can I write this code with wpcf7 text tag.
<input type="text" name="name" id="name" value="" onchange="this.setAttribute('value',this.value);" required/>
All what I could do is this
[text* name id:name]
my question is how can I add onchange to this text input ?
Share Improve this question edited Dec 14, 2020 at 0:28 Aurovrata 1,34611 silver badges18 bronze badges asked Dec 12, 2020 at 9:44 ZakiZaki 11 silver badge1 bronze badge 1- Please ask this kind of question on the Stack overflow forum instead. The WordPress forum isn't for plugins related issues. – Aurovrata Commented Dec 13, 2020 at 17:25
1 Answer
Reset to default 1The CF7 plugin does not give you access to the HTML markup formatting function of the field tags. So you need to capture the JavaScript event fired when the field is changed. To do this you can tag a script at the end of your form,
<label>[text* name id:name]</label>
<label>[text* surname id:surname]</label>
[submit]
<script>
(function($){
'use strict';
$(document).ready( function(){
$('form.wpcf7-form :input').change(function(e){
var $field = $(e.target);
switch($field.attr('name')){
case 'name': //text field name was changed.
//do something.
break;
case 'surname': //text field surname was changed.
//do something.
break;
}
})
})
})(jQuery)
</script>
本文标签: javascriptHow to add quoton changequot to a text input in contact form7
版权声明:本文标题:javascript - How to add "on change" to a text input in contact form7? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741921246a2405017.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论