Zen Cart Logo
Forums / General Questions / Zones Sort order in create account dropdown

Zones Sort order in create account dropdown

Views: 446

Results 1 to 3 of 3
18 Sep 2015, 10:19 AM
#1
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Zones Sort order in create account dropdown

I have a set of zones set up for UK Counties and regions and they display like this in the state dropdown(s)

<select name="zone_id" id="stateZone"> <option value="" selected="selected">Please select ...</option> <option value="135">Alderney, Channel Islands</option> <option value="74">Angus, Scotland</option> <option value="101">Antrim, Northern Ireland</option> <option value="73">Argyll, Scotland</option> <option value="102">Armagh, Northern Ireland</option> <option value="83">Ayrshire, Scotland</option> <option value="1">Bedfordshire, England</option>

How would I sort them in order of the value? like this

<select name="zone_id" id="stateZone"> <option value="" selected="selected">Please select ...</option> <option value="1">Bedfordshire, England</option> <option value="73">Argyll, Scotland</option> <option value="74">Angus, Scotland</option> <option value="83">Ayrshire, Scotland</option> <option value="101">Antrim, Northern Ireland</option> <option value="102">Armagh, Northern Ireland</option> <option value="135">Alderney, Channel Islands</option>

The reason I want to do this is so England is grouped as England Counties, Wales as Welsh Counties, Scotland as Scottish Counties, Ireland as Irish Counties, and Channel Islands...basically so they are grouped

18 Sep 2015, 10:45 AM
#2
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Zones Sort order in create account dropdown

The quickest way, but possibly not the best is to go to includes/functio/nsfunctions_general.php and
find```php
function zen_get_country_zones($country_id) {
global $db;
$zones_array = array();
$zones = $db->Execute("select zone_id, zone_name
from " . TABLE_ZONES . "
where zone_country_id = '" . (int)$country_id . "'
order by zone_name");
while (!$zones->EOF) {
$zones_array[] = array('id' => $zones->fields['zone_id'],
'text' => $zones->fields['zone_name']);
$zones->MoveNext();
}


you can change that to
```php
  function zen_get_country_zones($country_id) {
    global $db;
    $zones_array = array();
    $zones = $db->Execute("select zone_id, zone_name
                           from " . TABLE_ZONES . "
                           where zone_country_id = '" . (int)$country_id . "'
                           order by zone_id");
    while (!$zones->EOF) {
      $zones_array[] = array('id' => $zones->fields['zone_id'],
                             'text' => $zones->fields['zone_name']);
      $zones->MoveNext();
    }

that should work.

18 Sep 2015, 2:23 PM
#3
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Zones Sort order in create account dropdown

That did work and after implementing it the drodown was generated in the correct order like this.

<select name="zone_id" id="stateZone"> <option value="" selected="selected">Please select ...</option> <option value="1">Bedfordshire, England</option> <option value="2">Berkshire, England</option> <option value="3">Bristol, England</option> <option value="4">Buckinghamshire, England</option> <option value="5">Cambridgeshire, England</option> <option value="6">Cheshire, England</option> <option value="7">City of London, England</option> <option value="8">Cornwall, England</option> <option value="9">Cumbria, England</option> <option value="10">Derbyshire, England</option> <option value="11">Devon, England</option> <option value="12">Dorset, England</option> <option value="13">County Durham, England</option> <option value="14">East Riding of Yorkshire, England</option> <option value="15">East Sussex, England</option> <option value="16">Essex, England</option> <option value="17">Gloucestershire, England</option> <option value="18">Greater London, England</option> <option value="19">Greater Manchester, England</option> <option value="20">Hampshire, England</option> <option value="21">Herefordshire, England</option> <option value="22">Hertfordshire, England</option> <option value="23">Isle of Wight, England</option> <option value="24">Isle of Man, England</option> <option value="25">Kent, England</option> <option value="26">Lancashire, England</option> <option value="27">Leicestershire, England</option> <option value="28">Lincolnshire, England</option> <option value="29">Merseyside, England</option> <option value="30">Norfolk, England</option> <option value="31">North East Lincolnshire, England</option> <option value="32">North Yorkshire, England</option> <option value="33">Northamptonshire, England</option> <option value="34">Northumberland, England</option> <option value="35">Nottinghamshire, England</option> <option value="36">Oxfordshire, England</option> <option value="37">Rutland, England</option> <option value="38">Shropshire, England</option> <option value="39">Somerset, England</option> <option value="40">South Yorkshire, England</option> <option value="41">Staffordshire, England</option> <option value="42">Suffolk, England</option> <option value="43">Surrey, England</option> <option value="44">Tyne and Wear, England</option> <option value="45">Warwickshire, England</option> <option value="46">West Midlands, England</option> <option value="47">West Sussex, England</option> <option value="48">West Yorkshire, England</option> <option value="49">Wiltshire, England</option> <option value="50">Worcestershire, England</option> <option value="51">Merthyr Tydfil/Merthyr Tudful, Wales</option> <option value="52">Caerphilly/Caerffili, Wales</option> <option value="53">Blaenau Gwent, Wales</option> <option value="54">Torfaen/Tor-faen, Wales</option> <option value="55">Monmouthshire/Sir Fynwy, Wales</option> <option value="56">Newport/Casnewydd, Wales</option> <option value="57">Cardiff/Caerdydd, Wales</option> <option value="58">Vale of Glamorgan/Bro Morgannwg, Wales</option> <option value="59">Bridgend/Pen-y-bont ar Ogwr, Wales</option> <option value="60">Rhondda Cynon Taff/Rhondda Cynon T?f, Wales</option> <option value="61">Neath Port Talbot/Castell-nedd Port Talbot, Wales</option> <option value="62">Swansea/Abertawe, Wales</option> <option value="63">Carmarthenshire/Sir Gaerfyrddin, Wales</option> <option value="64">Ceredigion, Wales</option> <option value="65">Powys, Wales</option> <option value="66">Wrexham/Wrecsam, Wales</option> <option value="67">Flintshire/Sir y Fflint, Wales</option> <option value="68">Denbighshire/Sir Ddinbych, Wales</option> <option value="69">Conwy, Wales</option> <option value="70">Gwynedd, Wales</option> <option value="71">Isle of Anglesey/Ynys M?n, Wales</option> <option value="72">Pembrokeshire/Sir Benfro, Wales</option> <option value="73">Argyll, Scotland</option> <option value="74">Angus, Scotland</option> <option value="75">Sutherland, Scotland</option> <option value="76">Stirlingshire, Scotland</option> <option value="77">Dunbartonshire, Scotland</option> <option value="78">Bute, Scotland</option> <option value="79">Kirkcudbrightshire, Scotland</option> <option value="80">Peeblesshire, Scotland</option> <option value="81">Selkirkshire, Scotland</option> <option value="82">Dumfriesshire, Scotland</option> <option value="83">Ayrshire, Scotland</option> <option value="84">Kincardineshire, Scotland</option> <option value="85">Lanarkshire, Scotland</option> <option value="86">Roxburghshire, Scotland</option> <option value="87">Clackmannanshire, Scotland</option> <option value="88">Moray, Scotland</option> <option value="89">Caithness, Scotland</option> <option value="90">Nairnshire, Scotland</option> <option value="91">Midlothian, Scotland</option> <option value="92">East Lothian, Scotland</option> <option value="93">Berwickshire, Scotland</option> <option value="94">Fife, Scotland</option> <option value="95">Renfrewshire, Scotland</option> <option value="96">Kinross-shire, Scotland</option> <option value="97">Orkney, Scotland</option> <option value="98">Shetland, Scotland</option> <option value="99">Wigtownshire, Scotland</option> <option value="100">West Lothian, Scotland</option> <option value="101">Antrim, Northern Ireland</option> <option value="102">Armagh, Northern Ireland</option> <option value="103">Down, Northern Ireland</option> <option value="104">Fermanagh, Northern Ireland</option> <option value="105">Londonderry, Northern Ireland</option> <option value="106">Tyrone, Northern Ireland</option> <option value="107">Carlow, Southern Ireland</option> <option value="108">Cavan, Southern Ireland</option> <option value="109">Clare, Southern Ireland</option> <option value="110">Cork, Southern Ireland</option> <option value="111">Donegal, Southern Ireland</option> <option value="112">Dublin, Southern Ireland</option> <option value="113">Galway, Southern Ireland</option> <option value="114">Kerry, Southern Ireland</option> <option value="115">Kildare, Southern Ireland</option> <option value="116">Kilkenny, Southern Ireland</option> <option value="117">Laois, Southern Ireland</option> <option value="118">Leitrim, Southern Ireland</option> <option value="119">Limerick, Southern Ireland</option> <option value="120">Longford, Southern Ireland</option> <option value="121">Louth, Southern Ireland</option> <option value="122">Mayo, Southern Ireland</option> <option value="123">Meath, Southern Ireland</option> <option value="124">Monaghan, Southern Ireland</option> <option value="125">Offaly, Southern Ireland</option> <option value="126">Roscommon, Southern Ireland</option> <option value="127">Sligo, Southern Ireland</option> <option value="128">Tipperary, Southern Ireland</option> <option value="129">Waterford, Southern Ireland</option> <option value="130">Westmeath, Southern Ireland</option> <option value="131">Wexford, Southern Ireland</option> <option value="132">Wicklow, Southern Ireland</option> <option value="133">Jersey, Channel Islands</option> <option value="134">Guernsey, Channel Islands</option> <option value="135">Alderney, Channel Islands</option> <option value="136">Sark, Channel Islands</option> <option value="137">Herm, Channel Islands</option> <option value="138">Jethou, Channel Islands</option> </select>

However there is also Javascript in the header for this dropdown which seems to be forcing the display order back to alphabetical rather than numerical in order of the ID. This is the javascript.

<script language="javascript" type="text/javascript"><!-- function update_zone(theForm) { // if there is no zone_id field to update, or if it is hidden from display, then exit performing no updates if (!theForm || !theForm.elements["zone_id"]) return; if (theForm.zone_id.type == "hidden") return; // set initial values var SelectedCountry = theForm.zone_country_id.options[theForm.zone_country_id.selectedIndex].value; var SelectedZone = theForm.elements["zone_id"].value; // reset the array of pulldown options so it can be repopulated var NumState = theForm.zone_id.options.length; while(NumState > 0) { NumState = NumState - 1; theForm.zone_id.options[NumState] = null; } // build dynamic list of countries/zones for pulldown if (SelectedCountry == "222") { theForm.zone_id.options[0] = new Option("Please select ...", ""); theForm.zone_id.options[1] = new Option("Alderney, Channel Islands", "135"); theForm.zone_id.options[2] = new Option("Angus, Scotland", "74"); theForm.zone_id.options[3] = new Option("Antrim, Northern Ireland", "101"); theForm.zone_id.options[4] = new Option("Argyll, Scotland", "73"); theForm.zone_id.options[5] = new Option("Armagh, Northern Ireland", "102"); theForm.zone_id.options[6] = new Option("Ayrshire, Scotland", "83"); theForm.zone_id.options[7] = new Option("Bedfordshire, England", "1"); theForm.zone_id.options[8] = new Option("Berkshire, England", "2"); theForm.zone_id.options[9] = new Option("Berwickshire, Scotland", "93"); theForm.zone_id.options[10] = new Option("Blaenau Gwent, Wales", "53"); theForm.zone_id.options[11] = new Option("Bridgend/Pen-y-bont ar Ogwr, Wales", "59"); theForm.zone_id.options[12] = new Option("Bristol, England", "3"); theForm.zone_id.options[13] = new Option("Buckinghamshire, England", "4"); theForm.zone_id.options[14] = new Option("Bute, Scotland", "78"); theForm.zone_id.options[15] = new Option("Caerphilly/Caerffili, Wales", "52"); theForm.zone_id.options[16] = new Option("Caithness, Scotland", "89"); theForm.zone_id.options[17] = new Option("Cambridgeshire, England", "5"); theForm.zone_id.options[18] = new Option("Cardiff/Caerdydd, Wales", "57"); theForm.zone_id.options[19] = new Option("Carlow, Southern Ireland", "107"); theForm.zone_id.options[20] = new Option("Carmarthenshire/Sir Gaerfyrddin, Wales", "63"); theForm.zone_id.options[21] = new Option("Cavan, Southern Ireland", "108"); theForm.zone_id.options[22] = new Option("Ceredigion, Wales", "64"); theForm.zone_id.options[23] = new Option("Cheshire, England", "6"); theForm.zone_id.options[24] = new Option("City of London, England", "7"); theForm.zone_id.options[25] = new Option("Clackmannanshire, Scotland", "87"); theForm.zone_id.options[26] = new Option("Clare, Southern Ireland", "109"); theForm.zone_id.options[27] = new Option("Conwy, Wales", "69"); theForm.zone_id.options[28] = new Option("Cork, Southern Ireland", "110"); theForm.zone_id.options[29] = new Option("Cornwall, England", "8"); theForm.zone_id.options[30] = new Option("County Durham, England", "13"); theForm.zone_id.options[31] = new Option("Cumbria, England", "9"); theForm.zone_id.options[32] = new Option("Denbighshire/Sir Ddinbych, Wales", "68"); theForm.zone_id.options[33] = new Option("Derbyshire, England", "10"); theForm.zone_id.options[34] = new Option("Devon, England", "11"); theForm.zone_id.options[35] = new Option("Donegal, Southern Ireland", "111"); theForm.zone_id.options[36] = new Option("Dorset, England", "12"); theForm.zone_id.options[37] = new Option("Down, Northern Ireland", "103"); theForm.zone_id.options[38] = new Option("Dublin, Southern Ireland", "112"); theForm.zone_id.options[39] = new Option("Dumfriesshire, Scotland", "82"); theForm.zone_id.options[40] = new Option("Dunbartonshire, Scotland", "77"); theForm.zone_id.options[41] = new Option("East Lothian, Scotland", "92"); theForm.zone_id.options[42] = new Option("East Riding of Yorkshire, England", "14"); theForm.zone_id.options[43] = new Option("East Sussex, England", "15"); theForm.zone_id.options[44] = new Option("Essex, England", "16"); theForm.zone_id.options[45] = new Option("Fermanagh, Northern Ireland", "104"); theForm.zone_id.options[46] = new Option("Fife, Scotland", "94"); theForm.zone_id.options[47] = new Option("Flintshire/Sir y Fflint, Wales", "67"); theForm.zone_id.options[48] = new Option("Galway, Southern Ireland", "113"); theForm.zone_id.options[49] = new Option("Gloucestershire, England", "17"); theForm.zone_id.options[50] = new Option("Greater London, England", "18"); theForm.zone_id.options[51] = new Option("Greater Manchester, England", "19"); theForm.zone_id.options[52] = new Option("Guernsey, Channel Islands", "134"); theForm.zone_id.options[53] = new Option("Gwynedd, Wales", "70"); theForm.zone_id.options[54] = new Option("Hampshire, England", "20"); theForm.zone_id.options[55] = new Option("Herefordshire, England", "21"); theForm.zone_id.options[56] = new Option("Herm, Channel Islands", "137"); theForm.zone_id.options[57] = new Option("Hertfordshire, England", "22"); theForm.zone_id.options[58] = new Option("Isle of Anglesey/Ynys M?n, Wales", "71"); theForm.zone_id.options[59] = new Option("Isle of Man, England", "24"); theForm.zone_id.options[60] = new Option("Isle of Wight, England", "23"); theForm.zone_id.options[61] = new Option("Jersey, Channel Islands", "133"); theForm.zone_id.options[62] = new Option("Jethou, Channel Islands", "138"); theForm.zone_id.options[63] = new Option("Kent, England", "25"); theForm.zone_id.options[64] = new Option("Kerry, Southern Ireland", "114"); theForm.zone_id.options[65] = new Option("Kildare, Southern Ireland", "115"); theForm.zone_id.options[66] = new Option("Kilkenny, Southern Ireland", "116"); theForm.zone_id.options[67] = new Option("Kincardineshire, Scotland", "84"); theForm.zone_id.options[68] = new Option("Kinross-shire, Scotland", "96"); theForm.zone_id.options[69] = new Option("Kirkcudbrightshire, Scotland", "79"); theForm.zone_id.options[70] = new Option("Lanarkshire, Scotland", "85"); theForm.zone_id.options[71] = new Option("Lancashire, England", "26"); theForm.zone_id.options[72] = new Option("Laois, Southern Ireland", "117"); theForm.zone_id.options[73] = new Option("Leicestershire, England", "27"); theForm.zone_id.options[74] = new Option("Leitrim, Southern Ireland", "118"); theForm.zone_id.options[75] = new Option("Limerick, Southern Ireland", "119"); theForm.zone_id.options[76] = new Option("Lincolnshire, England", "28"); theForm.zone_id.options[77] = new Option("Londonderry, Northern Ireland", "105"); theForm.zone_id.options[78] = new Option("Longford, Southern Ireland", "120"); theForm.zone_id.options[79] = new Option("Louth, Southern Ireland", "121"); theForm.zone_id.options[80] = new Option("Mayo, Southern Ireland", "122"); theForm.zone_id.options[81] = new Option("Meath, Southern Ireland", "123"); theForm.zone_id.options[82] = new Option("Merseyside, England", "29"); theForm.zone_id.options[83] = new Option("Merthyr Tydfil/Merthyr Tudful, Wales", "51"); theForm.zone_id.options[84] = new Option("Midlothian, Scotland", "91"); theForm.zone_id.options[85] = new Option("Monaghan, Southern Ireland", "124"); theForm.zone_id.options[86] = new Option("Monmouthshire/Sir Fynwy, Wales", "55"); theForm.zone_id.options[87] = new Option("Moray, Scotland", "88"); theForm.zone_id.options[88] = new Option("Nairnshire, Scotland", "90"); theForm.zone_id.options[89] = new Option("Neath Port Talbot/Castell-nedd Port Talbot, Wales", "61"); theForm.zone_id.options[90] = new Option("Newport/Casnewydd, Wales", "56"); theForm.zone_id.options[91] = new Option("Norfolk, England", "30"); theForm.zone_id.options[92] = new Option("North East Lincolnshire, England", "31"); theForm.zone_id.options[93] = new Option("North Yorkshire, England", "32"); theForm.zone_id.options[94] = new Option("Northamptonshire, England", "33"); theForm.zone_id.options[95] = new Option("Northumberland, England", "34"); theForm.zone_id.options[96] = new Option("Nottinghamshire, England", "35"); theForm.zone_id.options[97] = new Option("Offaly, Southern Ireland", "125"); theForm.zone_id.options[98] = new Option("Orkney, Scotland", "97"); theForm.zone_id.options[99] = new Option("Oxfordshire, England", "36"); theForm.zone_id.options[100] = new Option("Peeblesshire, Scotland", "80"); theForm.zone_id.options[101] = new Option("Pembrokeshire/Sir Benfro, Wales", "72"); theForm.zone_id.options[102] = new Option("Powys, Wales", "65"); theForm.zone_id.options[103] = new Option("Renfrewshire, Scotland", "95"); theForm.zone_id.options[104] = new Option("Rhondda Cynon Taff/Rhondda Cynon T?f, Wales", "60"); theForm.zone_id.options[105] = new Option("Roscommon, Southern Ireland", "126"); theForm.zone_id.options[106] = new Option("Roxburghshire, Scotland", "86"); theForm.zone_id.options[107] = new Option("Rutland, England", "37"); theForm.zone_id.options[108] = new Option("Sark, Channel Islands", "136"); theForm.zone_id.options[109] = new Option("Selkirkshire, Scotland", "81"); theForm.zone_id.options[110] = new Option("Shetland, Scotland", "98"); theForm.zone_id.options[111] = new Option("Shropshire, England", "38"); theForm.zone_id.options[112] = new Option("Sligo, Southern Ireland", "127"); theForm.zone_id.options[113] = new Option("Somerset, England", "39"); theForm.zone_id.options[114] = new Option("South Yorkshire, England", "40"); theForm.zone_id.options[115] = new Option("Staffordshire, England", "41"); theForm.zone_id.options[116] = new Option("Stirlingshire, Scotland", "76"); theForm.zone_id.options[117] = new Option("Suffolk, England", "42"); theForm.zone_id.options[118] = new Option("Surrey, England", "43"); theForm.zone_id.options[119] = new Option("Sutherland, Scotland", "75"); theForm.zone_id.options[120] = new Option("Swansea/Abertawe, Wales", "62"); theForm.zone_id.options[121] = new Option("Tipperary, Southern Ireland", "128"); theForm.zone_id.options[122] = new Option("Torfaen/Tor-faen, Wales", "54"); theForm.zone_id.options[123] = new Option("Tyne and Wear, England", "44"); theForm.zone_id.options[124] = new Option("Tyrone, Northern Ireland", "106"); theForm.zone_id.options[125] = new Option("Vale of Glamorgan/Bro Morgannwg, Wales", "58"); theForm.zone_id.options[126] = new Option("Warwickshire, England", "45"); theForm.zone_id.options[127] = new Option("Waterford, Southern Ireland", "129"); theForm.zone_id.options[128] = new Option("West Lothian, Scotland", "100"); theForm.zone_id.options[129] = new Option("West Midlands, England", "46"); theForm.zone_id.options[130] = new Option("West Sussex, England", "47"); theForm.zone_id.options[131] = new Option("West Yorkshire, England", "48"); theForm.zone_id.options[132] = new Option("Westmeath, Southern Ireland", "130"); theForm.zone_id.options[133] = new Option("Wexford, Southern Ireland", "131"); theForm.zone_id.options[134] = new Option("Wicklow, Southern Ireland", "132"); theForm.zone_id.options[135] = new Option("Wigtownshire, Scotland", "99"); theForm.zone_id.options[136] = new Option("Wiltshire, England", "49"); theForm.zone_id.options[137] = new Option("Worcestershire, England", "50"); theForm.zone_id.options[138] = new Option("Wrexham/Wrecsam, Wales", "66"); hideStateField(theForm); } else { theForm.zone_id.options[0] = new Option("Type a choice below ...", ""); showStateField(theForm); } // if we had a value before reset, set it again if (SelectedZone != "") theForm.elements["zone_id"].value = SelectedZone; } function hideStateField(theForm) { theForm.state.disabled = true; theForm.state.className = 'hiddenField'; theForm.state.setAttribute('className', 'hiddenField'); document.getElementById("stateLabel").className = 'hiddenField'; document.getElementById("stateLabel").setAttribute('className', 'hiddenField'); document.getElementById("stText").className = 'hiddenField'; document.getElementById("stText").setAttribute('className', 'hiddenField'); document.getElementById("stBreak").className = 'hiddenField'; document.getElementById("stBreak").setAttribute('className', 'hiddenField'); } function showStateField(theForm) { theForm.state.disabled = false; theForm.state.className = 'inputLabel visibleField'; theForm.state.setAttribute('className', 'visibleField'); document.getElementById("stateLabel").className = 'inputLabel visibleField'; document.getElementById("stateLabel").setAttribute('className', 'inputLabel visibleField'); document.getElementById("stText").className = 'alert visibleField'; document.getElementById("stText").setAttribute('className', 'alert visibleField'); document.getElementById("stBreak").className = 'clearBoth visibleField'; document.getElementById("stBreak").setAttribute('className', 'clearBoth visibleField'); } //--></script>