0

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'); 
   }
5
  • Please give some context to this question or be more specific. I, for one, am not very sure what you're asking and how your code sample relates to your question. Perhaps you're just looking for the onChange event of the Dojo combo box? dojotoolkit.org/api/#1_10dijit_form_ComboBox_onChange
    – janechii
    Oct 6, 2014 at 22:38
  • No, I have an application where citizens are to choose the type of service that is needed. I.E. multi-family refuse, I would like a combo box to pre-populate with other fields such as location, curb side, etc.... Oct 6, 2014 at 23:21
  • This still sounds like using onchange event on your combo box will do the trick: dijit.byId('foo').on('change', function (val) { ... if (val == 1) bar = 3; else bar = 2; ... }
    – janechii
    Oct 6, 2014 at 23:37
  • I see, I will give this a shot! Oct 7, 2014 at 0:08
  • what does bar = 3 indicate here? Oct 7, 2014 at 18:17

1 Answer 1

4

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'); 
    }
  });
7
  • thank you for this @janechii I am having trouble understanding what 'value' indicates. Oct 7, 2014 at 19:15
  • ah... the set method takes 2 arguments: the attribute you want the set and the value of that attribute. set('value', '...') is equiv to setValue('...').
    – janechii
    Oct 7, 2014 at 19:54
  • I see, thanks again, please see my updated code sample, I am receving an error which notes an unexpected token at line 2 after (MFValue) {. Oct 7, 2014 at 19:56
  • see my updated answer. you're running into some syntax issues, which is beyond the scope of this question, but I hope with the example, you'll get the idea. The word function there is not a placeholder, but a required keyword to define an anonymous function. Do not change that.
    – janechii
    Oct 7, 2014 at 21:35
  • 1
    @GeoffreyWest if this answer helped, don't forget to mark it as the accepted answer by clicking the grey tick mark next to the vote up/down buttons on the left Oct 7, 2014 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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