Avatar of David Schure
David Schure

asked on 

Cleaning Up An Array

I am trying to clean this array up by removing the [""] tags.  Every time I do the code breaks.
There are two select boxes.  First one chooses the region, "United States", "India",etc.  Then the next one chooses the "State", etc.

<script>
	var stateObject = {
		
	"India": {"Delhi": ["", ""],"Kerala": ["", ""],"Goa": ["", ""],},
	
	"United States": {"Alabama": [""],"Alaska": [""],"Idaho": [""],},
	
	"Australia": {"South Australia": [""],"Victoria": [""]},
	
	"Canada": {"Alberta": [""],"Columbia": [""]},
	}
	window.onload = function () {
	var countySel = document.getElementById("countySel"),
	stateSel = document.getElementById("stateSel")
	for (var country in stateObject) {
	countySel.options[countySel.options.length] = new Option(country, country);
	}
	countySel.onchange = function () {
	stateSel.length = 1;
	if (this.selectedIndex < 1) return;
	for (var state in stateObject[this.value]) {
	stateSel.options[stateSel.options.length] = new Option(state, state);
	}
	}
	}
	</script>

Open in new window

JavaScript

Avatar of undefined
Last Comment
Chris Stanyon

8/22/2022 - Mon