AnsweredAssumed Answered

How to  get unique values from  an only field and display in a listbox

Question asked by d.diezr on Jun 17, 2015
Latest reply on Jun 21, 2015 by d.diezr

I am trying to  get unique values from  an only field from a  service and after displaying field values in a listbox.


Here ( )there is an example that shows several fields in a first listbox, and after shows the fields values in a second listboxs


How could i do the same but with an only FIELD instead of an array of field.  I only need to display the values of an only field in a listbox.


Anyone could help??? Any idea about how to subsitute ana array of fields per an single field in this code html??


Thank you very much. I am not developer and this is quite difficult for me


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"



<html lang="en">


  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">



  <script type="text/javascript" src=""></script>


  <script type="text/javascript" charset="utf-8">




  var queryTask, query;


  function init() {

  queryTask = new esri.tasks.QueryTask("");


  query = new esri.tasks.Query();

  query.where = "1=1";







  function getFieldList() {


  url: "",

  content: { f:"json" },

  handleAs: "json",

  callbackParamName: "callback",

  load: function(response, io) {

  var fields = response.fields;

  var options = [];

  dojo.forEach(fields, function(field) {

  options.push("<option value=\"" + + "\">" + field.alias + "</option>");


  dojo.byId("fields").innerHTML = options.join("");


  error: function(error) {






  function getFieldValues(field) {

  query.outFields = [field];

  queryTask.execute(query, dojo.partial(displayValues, field));



  function displayValues(field, featureSet) {

  var options = [], values = [], value;

  dojo.forEach(featureSet.features, function(feature) {

  value = feature.attributes[field];


  //add all values

  // options.push("<option value=\"" + value + ">" + value + "</option>");


  //filter values to only display unique values

  if (dojo.indexOf(values, value) == -1) {


  options.push("<option value=\"" + value + "\">" + value + "</option>");




  dojo.byId("values").innerHTML = options.join("");






  <select id="fields" onchange="getFieldValues(this.value);"></select>

  <select id="values" onchange="getFieldValues(this.value);"></select>