Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to set up autocomplete on a text box using jquery autocomplete with data from an arcserver service. I'm wondering if this is possible and if so how i would implement it. I'm using the esri javascript api v3.3 and arcserver 10.1.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Essentially, you are just passing an array to the autocomplete widget. If the data is in a map or feature service, query for the data from the service. If you start with a table in your mxd/msd that contains the data, when you publish it, you will get a REST endpoint for the table to query for in the same way. Next, parse out the data and push onto an array and pass it to the autocomplete widget.

    //build query task
    var queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3");
    //create an array
    var aStateNames = [];

    //build query filter
    var query = new esri.tasks.Query();
    query.returnGeometry = false;
    query.outFields = ["STATE_NAME"];
    query.where = "OBJECTID > 0";
    queryTask.execute(query, function (results) {
        //parse results and add to autocomplete widget
        dojo.forEach(results.features, function(value, index){
             aStateNames.push(value.attributes.STATE_NAME);
        });
    }, function (error) {
        alert("Error: " + error);
    });
share|improve this answer
    
Excellent, that works exactly as i wanted. Thanks. –  Zachary Mar 7 '13 at 17:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.