Variable scope within function for querytask

Discussion created by amarsden on Mar 20, 2012
Latest reply on Mar 21, 2012 by jeff.pace

I'm trying to hack about with the query tasks to get a YEs/No reply to a simple question - does the point passed to a page fall within our area

I have code like (x & y get defined earlier from URL parameters)

 function checkus() {
  queryTask = new esri.tasks.QueryTask("http://<our server>/ArcGIS2/rest/services/eforms2/MapServer/0");
  var point = new esri.geometry.Point(x, y, new esri.SpatialReference({wkid:27700}));
  query = new esri.tasks.Query();
  query.returnGeometry = false;
  query.geometry = point 
  query.outFields = ["admin_name"];
  dojo.connect(queryTask, "onComplete", function (results) {
   if (results.features.length>0) {
    alert("In Our Area");
   else {    
    window.location = "NoUs.asp"


I am trying to insert a variable inside the the bit that looks for the number of records returned, but try as I can, I can't get the variable to be global, as soon as that part finishes, so, it appears does the variable.

I must be doing something totally daft here.