I have an asp.net page with a map and two controls. One control selects a state, populates the second control with the counties within that selected state. I select multiple counties and hit a button. The button fires of a javascript function, loopSelected(), to loop through the selected counties and create an array.
function loopSelected() {
//Define an array to store selected counties
var selectedArray = new Array();
var selObj = document.getElementById('countyListBox');
var i;
var count = 0;
for (i = 0; i < selObj.options.length; i++) {
if (selObj.options.selected) {
selectedArray[count] = selObj.options.value;
count++;
}
}
//Pass array to Query and Find functions
runCountyQuery(selectedArray);
doCountyFind();
}
The selectedArray is passed to another function, runCountyQuery, that performs the QueryTask to select the multiple counties.
function runCountyQuery(selectedArray) {
//Define a new Query and QueryTask
queryTask = new esri.tasks.QueryTask("http://hwvanad1287/ArcGIS/rest/services/tdat/Acs/MapServer/0");
//Create query parameters
query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["*"];
//Parse selectedArray for query.where clause
var strText;
var i;
var count = 0;
for (i = 0; i < selectedArray.length; i++) {
strText = selectedArray;
alert('strText[' + i + ']: ' + strText);
count++;
}
//This section actually runs the query. It's called by the loopSelected() function above.
//The query is run as a deferred process, and the results are returned to the showQueryResults function.
//The query's where clause is specified in the input field.
//query.where = document.getElementById("countyListBox").value;
//query.where = "GEOID = " + "'" + query.where + "'";
//query.where = "GEOID IN (" + "'13001','13003','13005'" + ")";
query.where = "GEOID IN (" + selectedArray + ")";
alert('query.where:' + query.where);
queryTask.execute(query, showQueryResults, errResults);
}
My problem is building the proper syntax for the query.where clause from the selectedArray. I would also like to find the easiest way to debug the results on execute. If there is an easier way to construct a query.where clause containing multiple values, I am all ears.Todd McNeilGeographerU.S. Department of Housing and Urban DevelopmentOffice of Policy Development and Research