Selecting polygons intersecting with another polygon

Discussion created by samirgambhir on Jan 23, 2011
Latest reply on Jun 17, 2011 by hzhu
I have been trying to make this code work for sometime which should have taken me less time than I have spent on it so far. My code looks up a zip code file, selects a zipcode based on user selection. Once selected, it highlights the selected zipcode (mycode works till this point very well) and runs a query on another file to select all census tracts that intersect with the selected zipcode boundary. My code stops short of selecting tracts based on zipcode selection. Any help to resolve this will be great! Here is my code:

function QueryByZip(Zip_ID){
  queryTask= new esri.tasks.QueryTask("");
  query = new esri.tasks.Query();
  query.where = "ZIP = '" + Zip_ID + "'";
  query.returnGeometry = true;
  query.outFields = ["ZIP"];
  dojo.connect(queryTask, "onComplete", zoomToZip);

function zoomToZip(featureSet){
var features = featureSet.features;
var zipGraphic;
  for (var i=0, il=features.length; i<il; i++) {
     zipGraphic = new esri.Graphic(features[i]);
  queryTask2= new esri.tasks.QueryTask("");
  query2 = new esri.tasks.Query();
  query2.geometry = zipGraphic.geometry;
  query2.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
  query2.returnGeometry = true;
  dojo.connect(queryTask2, "onComplete", selectTracts);

function selectTracts(featureSet) {
var featureTracts = featureSet.features;
var tractGraphic;
       for (var i=0, il=featureTracts.length; i<il; i++) {
     tractGraphic = new esri.Graphic(featureTracts[i]);;