URGENT HELP -JAVASCRIPT & Lookup tables!!
Hi We have the following Javascript to define which of our shipping methods are displayed based on the country the customer tells us they are in throughout the checkout process. It currently works faultlessly, however is limited to 1 Delivery method. We would like to offer 2 or 3 for UK, and 1 for the others, with the ability to maybe offer 2 or 3 for all of them eventually.
The script is as follows:-
[CODE]<script type="text/javascript">
function FilterDeliveryOptions() {
var shipmeth_radio = document.getElementsByName('sShipMeth');
if (!shipmeth_radio || shipmeth_radio.length == 0) return;
var json_shippingtable = [<BB1_SHIPPING_TABLE>];
var country_index = 0;
var postcode_index = 1;
var shippingid_index = 2;
var shipcountry = "<%=getCurrentAttribute('customer','shipcountry','')%>";
var shipzip = "<%=getCurrentAttribute('customer','shipzip','')%>";
var allowed_shippingid = new Array();
if (shipcountry == '' && shipzip == '') return;
var shippingtable = eval(json_shippingtable);
for (var i=0; i < shippingtable.length; i++) {
var re_country = new RegExp('^'+shippingtable[i][country_index]+'$', 'i');
if (re_country.test(shipcountry)) {
var re_postcode = new RegExp('^'+shippingtable[i][postcode_index], 'i');
if (re_postcode.test(shipzip)) {
allowed_shippingid[allowed_shippingid.length] = shippingtable[i][shippingid_index];
break;
}
}
}
for (var i=shipmeth_radio.length-1; i >= 0; i--) {
for (var j=0; j < allowed_shippingid.length; j++) {
if (shipmeth_radio[i].value != allowed_shippingid[j]) {
var node = shipmeth_radio[i].parentNode.parentNode;
node.parentNode.removeChild(node);
}
else {
var selected = shipmeth_radio[i];
}
}
}
if (selected && !selected.checked) selected.onclick();
}
FilterDeliveryOptions();
</script>[/CODE]
Now the "Shipping Table" is as follows, now this part seems relatively simple to amend, as we just need to add another comma, and the internal ID of our second shipping method.... But its getting the above script to understand that the red part is shipping method number 2 as an option:-
[CODE]["GB","BT","185",183],
["GB","FK1[8-9]","183"],
["GB","HS","183"],
["GB","IV","183"],
["GB","KA2[7-8]","183"],
["GB","KW","183"],
["GB","PA(([2-7][0-9])|(8[0-8]))","183"],
["GB","PH((1[7-9])|([2-4][0-9])|(50))","183"],
["GB","ZE","183"],
["GB","IM","184"],
["GB","PO((3[0-9])|(4[0-1]))","184"],
["GB","TR2[1-5]","184"],
["GB","BFPO","188"],
["GB","","181"],
["IE","","186"],
["JE","","187"],
["GG","","187"],
["AU","","10372"],
["AT","","189"],
["BE","","189"],
["BG","","10114"],
["HR","","10378"],
["CY","","10114"],
["CZ","","10113"],
["DK","","189"],
["EE","","10113"],
["FI","","189"],
["FR","","189"],
["DE","","189"],
["GI","","10376"],
["GR","","10114"],
["HU","","10113"],
["IT","","189"],
["LV","","10113"],
["LT","","10113"],
["LU","","189"],
["MT","","10114"],
["NL","","189"],
["NZ","","10372"],
["NO","","7316"],
["PL","","10113"],
["PT","","189"],
["RO","","10114"],
["SK","","10113"],
["SI","","10113"],
["ES","","189"],
["SE","","189"],
["CH","","10377"],
["SG","","14940"],
["TR","","10378"]["GB","BT","185"],
["GB","FK1[8-9]","183"],
["GB","HS","183"],
["GB","IV","183"],
["GB","KA2[7-8]","183"],
["GB","KW","183"],
["GB","PA(([2-7][0-9])|(8[0-8]))","183"],
["GB","PH((1[7-9])|([2-4][0-9])|(50))","183"],
["GB","ZE","183"],
["GB","IM","184"],
["GB","PO((3[0-9])|(4[0-1]))","184"],
["GB","TR2[1-5]","184"],
["GB","BFPO","188"],
["GB","","181"],
["IE","","186"],
["JE","","187"],
["GG","","187"],
["AU","","10372"],
["AT","","189"],
["BE","","189"],
["BG","","10114"],
["HR","","10378"],
["CY","","10114"],
["CZ","","10113"],
["DK","","189"],
["EE","","10113"],
["FI","","189"],
["FR","","189"],
["DE","","189"],
["GI","","10376"],
["GR","","10114"],
["HU","","10113"],
["IT","","189"],
["LV","","10113"],
["LT","","10113"],
["LU","","189"],
["MT","","10114"],
["NL","","189"],
["NZ","","10372"],
["NO","","7316"],
["PL","","10113"],
["PT","","189"],
["RO","","10114"],
["SK","","10113"],
["SI","","10113"],
["ES","","189"],
["SE","","189"],
["CH","","10377"],
["SG","","14940"],
["TR","","10378"][/CODE]
Any help would be VERY MUCH appreciated!!
Thank you!
-Matt