Expand my Community achievements bar.

Ship to and Bill to the same

Avatar

Former Community Member
Thanks for all the wonderful tips and tricks here...I've learned a lot. I am trying to create a check box that will automatically transfer the "Ship to" to the "Bill to" if the are the same. I can't seem to figure it out.



Here is an example:

http://www.wizzardweb.co.uk/java_copy_info.html



I've used the following code but to no avail:



var ShipToCompany = "";

var ShipToContact = "";

var ShipToAddress = "";

var ShipToCityStateZip = "";

var ShipToPhone = "";

var ShipToEmail = "";



function InitSaveVariables(form1) {

ShipToCompany = form1.ShipToCompany.value;

ShipToContact = form1.ShipToContact.value;

ShipToAddress = form1.ShipToAddress.value;

ShipToCityStateZip = form1.ShipToCityStateZip.value;

ShipToPhone = form1.ShipToPhone.value;

ShipToEmail = form1.ShipToEmail.value;

}



function infoCopy(form1) {

if (CheckBox1.copy.checked) {

InitSaveVariables(form1);

form1.ShipToCompany.value = form1.BillToCompany.value;

form1.ShipToContact.value = form1.BillToContact.value;

form1.ShipToAddress.value = form1.BillToAddress.value;

form1.ShipToCityStateZip.value = form1.BillToCityStateZip.value;

form1.ShipToPhone.value = form1.BillToPhone.value;

form1.ShipToEmail.value = form1.BillToEmail.value;

}

else {

form1.ShipToCompany.value = ShipToCompany;

form1.ShipToContact.value = ShipToContact;

form1.ShipToAddress.value = ShipToAddress;

form1.ShipToCityStateZip.value = ShipToCityStateZip;

form1.ShipToPhone.value = ShipToPhone;

form1.ShipToEmail.value = ShipToEmail;

}

}



Any help would be great appreciated.
4 Replies

Avatar

Former Community Member
First, you are using the 'value' property and you should be using the 'rawValue' property. Second, if a user has entered data into the Ship To form fields you don't need to create new variables to store them.



Here is the click event on my checkbox object called 'copy', where the checkbox has an On Value of 1 and an Off Value of 0.



if (this.rawValue == "1") {

form1.subform1.billToCompany.rawValue = form1.subform1.shipToCompany.rawValue;

form1.subform1.billToAddress.rawValue = form1.subform1.shipToAddress.rawValue;

form1.subform1.billToCity.rawValue = form1.subform1.shipToCity.rawValue;

}



Steve

Avatar

Former Community Member
Steve thanks for getting me started and the clarification. Still cannot get the data to move over. I think I'm over looking something.



form1.#subform[0].subform.CheckBox1::click - (JavaScript, client)



if (this.rawValue == "1") {

form1.subform1.BillToCompany.rawValue = form1.subform1.ShipToCompany.rawValue;

form1.subform1.BillToContact.rawValue = form1.subform1.ShipToContact.rawValue;

form1.subform1.BillToAddress.rawValue = form1.subform1.ShipToAddress.rawValue;

form1.subform1.BillToCityStateZip.rawValue = form1.subform1.ShipToCityStateZip.rawValue;

form1.subform1.BillToPhone.rawValue = form1.subform1.ShipToPhone.rawValue;

form1.subform1.BillToEmail.rawValue = form1.subform1.ShipToEmail.rawValue;

}

Avatar

Former Community Member
If you do not have a subform called subform1 than these fully-qualified object names will not work.



You can either



1. change the subform names in the script to match your subform name

2. reference the fields without the form and subform prefix, or

3. if the subform is untitled use the syntax form1.#subform[0].BillToCompany.rawValue, for example.



Steve

Avatar

Level 10
Hi TF,



A tip from JP Terry's (excellent) book!



When in the script editor you can hover over the field you want to reference. Pressing control will turn the cursor into a down arrow, then holding control and clicking the field will insert the object's reference directly in your script:

BillToCompany



If you hold control and shift, you will get a fully qualified reference:

xfa.resolveNode("xfa.form.form1.#subform[0].BillToCompany")



Try it out, as it helps ensure that the references are correct.



N.