1

I need to construct a drop down menu with each choice enabling a different geoprocessing task to run over my script.

<select id="myList" onchange="environment()">
   <option>Select..</option>
   <option value="http://********/arcgis/rest/services/EDDM/selectZIP/GPServer">DEV</option>
   <option value="http://********/arcgis/rest/services/EDDM/selectZIP/GPServer">SIT</option>  
   <option value="http://********/arcgis/rest/services/EDDM/selectZIP/GPServer">CAT</option>
   <option value="http://********/arcgis/rest/services/EDDM/selectZIP/GPServer">PROD</option>
</select>

They each run the same process albeit at different levels of production. I have this code that is a placeholder and uses just one value.

function selectZIP(Zip_code){
    gp = new esri.tasks.Geoprocessor("http://********/arcgis/rest/services/EDDM/selectZIP/GPServer/selectZIP"); 

How can I make a drop-down that will allow the user to select which GPServer they need and use it on the same script?

2

Working under the assumption you are using the latest ArcGIS JS API (3.5) with Dojo 1.8, you could use dojo/on and dojo/query to listen to the "change" event of the element.

require(['dojo/on', 'dojo/query'], function(on, query) {
    on(query('#myList'), 'change', function(e){
        var gpURL = e.target.value;
        console.log('list changed', gpURL);
        // call gp service with gpURL value
    });
});

You can then use the result of the e.target.value, which would be the URL in the dropdown to send to your Geoprocessor.

  • function selectZIP(Zip_code){ gp = new esri.tasks.Geoprocessor(gpURL);} So i would in turn make it like this? – Maksim Jun 20 '13 at 15:24
  • You have a couple of options. You could do it like that, creating a new Geoprocessor task with every dropdown change or create the Geoprocessor ahead of time and just change the URL each time and run your task. The docs don't say the URL is read-only. developers.arcgis.com/en/javascript/jsapi/geoprocessor-amd.html – Rene Rubalcava Jun 20 '13 at 17:04
  • I've tried what you posted above and it returns a "TypeError: this._url is undefined" In the console it logs the url for each option in my drop down as I change it so i've gotten that far. – Maksim Jun 20 '13 at 17:08
  • That probably means the Geoprocessor needs to has a URL in the constructor, so to get it working, I would use the method you listed above and create a new GP on every dropdown, get the functionality working then tweak it later if need be. – Rene Rubalcava Jun 20 '13 at 17:14
  • So what youre saying is i need 4 different gp = new esri.tasks.Geoprocessor("http://eddmapi-dev.usps.gov/arcgis/rest/services/EDDM/selectZIP/GPServer/selectZIP"); with the URL changed. Do i use some sort of if/else statement? First time working with this – Maksim Jun 20 '13 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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