The eCart should create a script file: WA_SameAs.js
That file has a function:
setSame(check, tofieldset, fromfieldset)
It depends on the tofieldset form element ID values to match the fromfieldset with "_2" appended.
An example would be:
<form>
<fieldset id="shipping">
<input id="first">
</fieldset>
<div>
<label>billing same as shipping <input type="checkbox" id="same" onclick="setSame(this, 'billing', 'shipping')"></label>
</div>
<fieldset id="billing">
<input id="first_2">
</fieldset>
</form>
<script>
function wa_fireEvent(element,event){
if (document.createEventObject){
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else{
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable
return !element.dispatchEvent(evt);
}
}
function findIndexFromID(id, fromfieldset) {
var theSourceFieldset = document.getElementById(fromfieldset);
var theSourceInputs = theSourceFieldset.getElementsByTagName("select");
for (var y=0; y<theSourceInputs.length; y++) {
if (stripEnum(theSourceInputs[y].id,fromfieldset) == id) {
return theSourceInputs[y].selectedIndex;
}
}
return 0;
}
function findFieldValueFromID(id, fromfieldset) {
var theSourceFieldset = document.getElementById(fromfieldset);
var theSourceInputs = theSourceFieldset.getElementsByTagName("input");
for (var y=0; y<theSourceInputs.length; y++) {
if (theSourceInputs[y].id == id) {
return theSourceInputs[y].value;
}
}
return false;
}
function stripEnum(theID,theStart) {
var retID = theID;
if (theID.indexOf(theStart)==0) {
retID = retID.substring(theStart.length);
}
if (retID.search(/_\d*$/)>0) {
retID = retID.substring(0,retID.lastIndexOf("_"));
}
return retID;
}
function setSame(check, tofieldset, fromfieldset) {
if (check.checked) {
var theDestinationFieldset = document.getElementById(tofieldset);
var theDestinationInputs = theDestinationFieldset.getElementsByTagName("input");
var theDestinationSelects = theDestinationFieldset.getElementsByTagName("select");
for (var x=0; x<theDestinationSelects.length; x++) {
theDestinationSelects[x].selectedIndex = findIndexFromID(stripEnum(theDestinationSelects[x].id,tofieldset), fromfieldset);
if (window.CountryChange && theDestinationSelects[x].id == "Country_2") CountryChange("_2");
wa_fireEvent(theDestinationSelects[x],"change");
}
for (var x=0; x<theDestinationInputs.length; x++) {
if (theDestinationInputs[x].type == "text") {
theDestinationInputs[x].value = findFieldValueFromID(stripEnum(theDestinationInputs[x].id,tofieldset), fromfieldset);
wa_fireEvent(theDestinationInputs[x],"blur");
}
}
}
}
</script>
If you find the WA_SameAs.js file, then you don't need to include the <script> tag in the above example... all of those functions are defined in that file.