Link to home
Start Free TrialLog in
Avatar of henry
henry Flag for United States of America

asked on

write code for check box in Adobe Form

Hello, 


I'm building PDF form. 

Have two sections : "Bill To" and "Ship To". 

"Bill To" have few fields: Company, Address, City, State, Zip, Country and Phone. 

"Ship To" has exactly same set of fields like above. 


Have also checkbox in "Ship To" section saying "same as Bill To".

I need a code what I can apply to checkbox:

if checkbox is checked copy all info from Bill To fields to Ship to fields. 


thank you for help, 


Henry


Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Here is a basic code in javascript to this..
First add an eventlistener to the checkbox element.
document.getElementById("sameAsBillTo").addEventListener("click", copyInfo);

Open in new window


And the function

function copyInfo() {
    // Get the checkbox element
    let checkbox = document.getElementById("sameAsBillTo");

    // Get the "Bill To" and "Ship To" fields
    let billToCompany = document.getElementById("billToCompany");
    let billToAddress = document.getElementById("billToAddress");
    
    let shipToCompany = document.getElementById("shipToCompany");
    let shipToAddress = document.getElementById("shipToAddress");
    
    // Check if the checkbox is checked
    if (checkbox.checked) {
        // Copy the information from the "Bill To" fields to the "Ship To" fields
        shipToCompany.value = billToCompany.value;
        shipToAddress.value = billToAddress.value;
     
    }
}

Open in new window

Avatar of henry

ASKER

I have some issue make your code work.
I created below and working pretty well, except:
Last two lines, entry for phone#  not working. Is any limitation in that kind of code how many lines I can use it ?
if I eliminate let say Country phone fields are working.

if (event.target.value=="Yes") {
      this.getField("CompanyST").value = this.getField("Company").value;
      this.getField("CompanyST").readonly = true;
     this.getField("AddressST").value = this.getField("Address").value;
      this.getField("AddressST").readonly = true;
     this.getField("CityST").value = this.getField("City").value;
      this.getField("CityST").readonly = true;
     this.getField("StateST").value = this.getField("StateProvince").value;
      this.getField("StateST").readonly = true;
     this.getField("AddressST").value = this.getField("Address").value;
      this.getField("AddressST").readonly = true;
     this.getField("ZIPST").value = this.getField("ZIP").value;
      this.getField("ZIPST").readonly = true;
     this.getField("CountryST").value = this.getField("Country").value;
      this.getField("countryST").readonly = true;
     this.getField("Phst").value = this.getField("Phone").value;
      this.getField("Phst").readonly = true;


}


Check your console for errors message and post it
ASKER CERTIFIED SOLUTION
Avatar of henry
henry
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial