troubleshooting Question

Cleaning Up An Array

Avatar of David Schure
David Schure asked on
JavaScript
9 Comments1 Solution18 ViewsLast Modified:
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>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros