Skip to main content
Participating Frequently
March 16, 2021
Answered

Help for fix script to populate ship to fields when I click same as above

  • March 16, 2021
  • 1 reply
  • 2923 views

Hi, in the attach pdf form. I've 3 fields in customer details section:

1. name

2. address

3. address2

I want to auto populate data from this 3 fields to "Ship to" section (bellow fields) if I click "SameAsAbove" checkbox:

1. Nameofshipping

2. Addressofshipping

2. Address2ofshipping

 

I've added bellow script in the chckbox field<Action<Mouse Up<Ran a Javascript&colon;

 

// check the state of the buttonif(this.getField(event.target.name).value == 'Yes') {// checked// copy address information// get each billing field object's value and set the shipping field's valuethis.getField('name').value = this.getField('nameofshipping').value;this.getField('address').value = this.getField('Addressofshipping').value;this.getField('Address2').value = this.getField('Address2ofshipping').value; // lock fields// set each shipping field's read only property to locked - truethis.getField('name').readonly = true;this.getField('address').readonly = true;this.getField('Address2').readonly = true;} else {// unchecked// unlock fields// set each shipping field's readonly property to unlocked - falsethis.getField('name').readonly = false;this.getField('address').readonly = false;this.getField('Address2').readonly = false;}

 

But the fucntion is not working. anyone could help me in this regard. BTW I've no idea about writing java script. However thanks in advance

 

 

This topic has been closed for replies.
Correct answer Bernd Alheit

Change the field calculation order.

1 reply

Nesa Nurani
Community Expert
Community Expert
March 16, 2021

Try this code:

if(event.target.value != "Off"){
this.getField("Nameofshipping").value = this.getField("Name").value;
this.getField("Addressofshipping").value = this.getField("Address").value;
this.getField("Address2ofshipping").value = this.getField("Address2").value;
this.getField("Nameofshipping").readonly = true;
this.getField("Addressofshipping").readonly = true;
this.getField("Address2ofshipping").readonly = true;}
else {
this.getField("Nameofshipping").value = "";
this.getField("Addressofshipping").value = "";
this.getField("Address2ofshipping").value = "";
this.getField("Nameofshipping").readonly = false;
this.getField("Addressofshipping").readonly = false;
this.getField("Address2ofshipping").readonly = false;}
Participating Frequently
July 15, 2022

what is the "event.target.value" ... and where does that go on the form itself?

Is this the name used for the "same as above checkbox" or should we use a BUTTON instead?

 

I have a very similar task where the client fills out there address info in the top table of fields and, if the top address is same as the next one down, they can autopopulate those fields based on the previous inputs above using the CHECK BOX on ... hope this makes sense.

 

Woody House

Participating Frequently
July 15, 2022

I am attaching a screenshot of my actual PDF in production ...

 

You should see 3 tables of fields where we collect the user's address details ... the logic here is:

 

They ALL fill out the top field in all cases

If the first table with fields has the same address specs, they use the checkbox above that table to auto populate

If the second table with fields has the same address specs as the first table NOT the top table ... they check that box to auto populate

 

Nesa's basic script is working but we have two checkboxes to contend with here ...

 

Thanks heaps!