Get values from twodimensional array - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Get values from twodimensional array

Posts: 326Member
[b][red]This message was edited by treshr at 2005-11-28 3:48:0[/red][/b][hr]
[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

var f = document.forms['test'];

var l = f.land.options.length;
var provincie = new Array(l);

for(i = 0; i < l.length; i++){
provincie[i] = new Array();
}

provincie[0][0] = "Kies eerst een land";

provincie[1][0] = "Kies een provincie";
provincie[1][1] = "Groningen";
provincie[1][2] = "Friesland";
provincie[1][3] = "Drenthe";
provincie[1][4] = "Gelderland";

var t = f.provincie;

function zetProvincies(x){
for(i = 0; i < provincie[x].length; i++){
t.options[i] = new Option(provincie[x][i], provincie[x][i]);
}
}

 Land: Geen Selectie Nederland Provincie:

[/code]

And i get the error that the provincie array is empty or is no object. Does anybody what I did wrong. I can do some things with Javascript but this I can't solve on my own.

--=][tReShR][=--

• Posts: 170Member
: [b][red]This message was edited by treshr at 2005-11-28 3:48:0[/red][/b][hr]
: [code]
: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
:
:
:
:
: var f = document.forms['test'];
:
: var l = f.land.options.length;
: var provincie = new Array(l);
:
: for(i = 0; i < l.length; i++){
: provincie[i] = new Array();
: }
:
: provincie[0][0] = "Kies eerst een land";
:
: provincie[1][0] = "Kies een provincie";
: provincie[1][1] = "Groningen";
: provincie[1][2] = "Friesland";
: provincie[1][3] = "Drenthe";
: provincie[1][4] = "Gelderland";
:
: var t = f.provincie;
:
: function zetProvincies(x){
: for(i = 0; i < provincie[x].length; i++){
: t.options[i] = new Option(provincie[x][i], provincie[x][i]);
: }
: }
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:  Land: : : Geen Selectie: Nederland: : Provincie: : : : :
:
:
:
: [/code]
:
: And i get the error that the provincie array is empty or is no object. Does anybody what I did wrong. I can do some things with Javascript but this I can't solve on my own.
:
:
: --=][tReShR][=--
:
:
:
:
:
:
:
:
:

Hi

Try this post :
• Posts: 326Member
That doesn't help me. I don't have the question how to create a twodimensional array but why my script keeps saying that there is no object or that it's empty.

--=][tReShR][=--

• Posts: 170Member
[b][red]This message was edited by NCS_One at 2005-11-28 8:32:5[/red][/b][hr]
: That doesn't help me. I don't have the question how to create a twodimensional array but why my script keeps saying that there is no object or that it's empty.
:
:
: --=][tReShR][=--
:
:

Hi

You are creating the array in the wrong way, you have to do it like this :
[code]
var provincie = [[1],[4]];
[/code]
Hope it helps.

• Posts: 100Member
This rather large code works like this:
In stead of filling a new select list every time you make a choice of country, fill a lot of select lists and display only the one chosen.

I guess it's a bit more complicated than your code needs to be if you are only choosing country once for each session.

PS. Please notice the difference between COUNTY and COUNTRY

[CODE][SIZE=2]

p = new Array();
p[leftbr]0[rightbr] = [leftbr]
"Kies een provincie",
"Groningen",
"Friesland",
"Drenthe",
"Gelderland"
[rightbr];
p[leftbr]0[rightbr].country = "Nederland";

p[leftbr]1[rightbr] = [leftbr]
"Choose a county",
"Bedfordshire",
"Berkshire",
"Buckinghamshire",
"Cambridgeshire",
"Cheshire",
"Cornwall",
"Cumberland",
"Derbyshire",
"Devon",
"Dorset",
"Durham",
"Essex",
"Gloucestershire",
"Hampshire",
"Herefordshire",
"Hertfordshire",
"Huntingdonshire",
"Kent",
"Lancashire",
"Leicestershire",
"Lincolnshire",
"Middlesex",
"Norfolk",
"Northamptonshire",
"Northumberland",
"Nottinghamshire",
"Oxfordshire",
"Rutland",
"Shropshire",
"Somerset",
"Staffordshire",
"Suffolk",
"Surrey",
"Sussex",
"Warwickshire",
"Westmorland",
"Wiltshire",
"Worcestershire",
"Yorkshire",
"Anglesey/Sir Fon",
"Brecknockshire/Sir Frycheiniog",
"Caernarfonshire/Sir Gaernarfon",
"Carmarthenshire/Sir Gaerfyrddin",
"Cardiganshire/Ceredigion",
"Denbighshire/Sir Ddinbych",
"Flintshire/Sir Fflint",
"Glamorgan/Morgannwg",
"Merioneth/Meirionnydd",
"Monmouthshire/Sir Fynwy",
"Montgomeryshire/Sir Drefaldwyn",
"Pembrokeshire/Sir Benfro",
"Aberdeenshire",
"Angus/Forfarshire",
"Argyllshire",
"Ayrshire",
"Banffshire",
"Berwickshire",
"Buteshire",
"Cromartyshire",
"Caithness",
"Clackmannanshire",
"Dumfriesshire",
"Dunbartonshire/Dumbartonshire",
"Fife",
"Inverness-shire",
"Kincardineshire",
"Kinross-shire",
"Kirkcudbrightshire",
"Lanarkshire",
"Midlothian/Edinburghshire",
"Morayshire",
"Nairnshire",
"Orkney",
"Peeblesshire",
"Perthshire",
"Renfrewshire",
"Ross-shire",
"Roxburghshire",
"Selkirkshire",
"Shetland",
"Stirlingshire",
"Sutherland",
"West Lothian/Linlithgowshire",
"Wigtownshire"[rightbr];
p[leftbr]1[rightbr].country = "Great Britain";

var displayedSelect = null;
function fillSelect() {
sel = document.getElementById("SELECT");
// Fill country SELECT
country = document.getElementById("COUNTRY");
opt = document.createElement("OPTION");
opt.innerHTML = "Choose a country";
country.appendChild(opt);

for(s=0;s

 Country: County: No country selected

[SIZE][/CODE]