Skip Navigation

[Resolved] copy field value to another field if checkbox checked

This support ticket is created 3 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Shane 3 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#2206655

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??

#2207339

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

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