Monday 21 November 2016

Creating if-else condition with ArcGIS API for JavaScript combo boxes?


I have an ArcGIS JavaScript API Web App that uses multiple combo boxes. I would like to create an if-else conditional statement between two fields in my feature layer. If one field is chosen in combo box one is 1 then combo box three should automatically populate to 3.


Below is my validate function for my request type.


 function changeonevent() {

(dijit.byId("cbRequestType").on('change'), changeonevent (MFValue) {
if (MFValue == 'Electronic Waste') {
dijit.byID("cbMFSubType"). set ('value', 'Copy Machine');
} else if MFValue == '...'{
dijit.by.ID('cbMFSubType').set('value', 'Printer');
}

Answer



Sorry for the concise comment, I can elaborate here. Say foo and bar are your combo box dijits:


dijit.byId('foo').on('change', function (new_value) {
if (new_value == 'multi_family_refuse') {

dijit.byId('bar').set('value', 'bar value 1');
} else if (new_value == '...') {
dijit.byId('bar').set('value', 'bar value 2');
} else {
...
}
});

if you have a lot of various states, try using switch statement instead.


Using your updated example:



  dijit.byId("cbRequestType").on('change', function (MFValue) {
if (MFValue == 'Electronic Waste') {
dijit.byID("cbMFSubType").set('value', 'Copy Machine');
} else if MFValue == '...'{
dijit.by.ID('cbMFSubType').set('value', 'Printer');
}
});

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...