Dears,
I have 2 fields and one checkbox.
[cred_field field='user_email' class='form-control' output='bootstrap' value=""]
[cred_field field="nickname" class="form-control" output="bootstrap" value = ""]
[cred_field field='agree' force_type='field' class='form-control' output='bootstrap' onclick='copyTextValue()']
I would like to copy the first field value into the second field when the checkbox is checked and before submitting the form. I have used the below code in JS of the user form.
function copyTextValue() {
if(document.querySelector("input[name='wpcf-agree']").checked){
var email = document.querySelector("input[name='user_email']").value;
document.querySelector("input[name='nickname']").value; = email;
}
}
we have tested the code it was working fine outside WordPress, but it is not working when I used it here. What is wrong with it??
Hi Salim,
Thank you for getting in touch.
Onclick is not a valid attribute for our Toolset Forms shortcodes. In order to implement your solution the best way is to trigger the jQuery trigger. See details below.
https://stackoverflow.com/questions/4780912/how-to-trigger-checkbox-click-event-even-if-its-checked-through-javascript-code
Please let me know if this helps or if further clarification is needed.
Thanks,
Shane