Skip to main content
Participant
October 15, 2021
Answered

Click a checkbox to copy content from one form field to another

  • October 15, 2021
  • 1 reply
  • 926 views

I am working on a form that will have 3 different sections — all with identical fields (“Attn”, “Company”, “ Address”, “City”, “State”, “Zip”, “Phone”, “Email”, etc). Each section may end up with different content, but may occasionally need to be the same. In this case, I would like the user to click a checkbox and have sections 2 & 3 auto-populate using the content from the fields in section 1. I am not versed in javascript, but I am hoping someone can give me a nudge in the right direction. Thanks in advance!

This topic has been closed for replies.
Correct answer Nesa Nurani

Try this:

if(event.target.value != "Off"){
this.getField("Attn_2").value = this.getField("Attn").value;
this.getField("Attn_3").value = this.getField("Attn").value;
this.getField("Company_2").value = this.getField("Company").value;
this.getField("Company_3").value = this.getField("Company").value;
this.getField("Delivery Address_2").value = this.getField("Delivery Address").value;
this.getField("Delivery Address_3").value = this.getField("Delivery Address").value;}

1 reply

Nesa Nurani
Community Expert
Community Expert
October 15, 2021

Lets say you have fields "Email1","Phone1" and "Email2","Phone2", as Mouse UP event of checkbox you can use script like this:

if(event.target.value != "Off"){
this.getField("Email2").value = this.getField("Email1").value;
this.getField("Phone2").value = this.getField("Phone1").value;}

Adapt code to your needs.

Participant
October 15, 2021

Thank you for your reply. I added the script to the checkbox actions and get an illegal character error in the JavaScript Editor (see highlighted line in screenshot). Pardon my ignorance on this.

 

 

Participant
October 15, 2021

Try this:

if(event.target.value != "Off"){
this.getField("Attn_2").value = this.getField("Attn").value;
this.getField("Attn_3").value = this.getField("Attn").value;
this.getField("Company_2").value = this.getField("Company").value;
this.getField("Company_3").value = this.getField("Company").value;
this.getField("Delivery Address_2").value = this.getField("Delivery Address").value;
this.getField("Delivery Address_3").value = this.getField("Delivery Address").value;}


Thank you so much for your help on this! This works exactly as I had hoped.