If then condition with combo boxes in JavaScript API?

1833
18
Jump to solution
10-07-2014 03:24 PM
GeoffreyWest
Occasional Contributor III

I am receiving a syntax error; unexpected identifier at line 5.  @

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');

    }

  });

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Geoffery,

  Try placing your else if condition in parens

  1. dijit.byId("cbRequestType").on('change', function (MFValue) { 
  2.     if (MFValue == 'Electronic Waste') { 
  3.     dijit.byID("cbMFSubType").set('value', 'Copy Machine');  
  4.     }   
  5.     else if (MFValue == '...')
  6.       dijit.by.ID('cbMFSubType').set('value', 'Printer');  
  7.     } 
  8.   });

View solution in original post

18 Replies
RobertScheitlin__GISP
MVP Emeritus

Geoffery,

  Try placing your else if condition in parens

  1. dijit.byId("cbRequestType").on('change', function (MFValue) { 
  2.     if (MFValue == 'Electronic Waste') { 
  3.     dijit.byID("cbMFSubType").set('value', 'Copy Machine');  
  4.     }   
  5.     else if (MFValue == '...')
  6.       dijit.by.ID('cbMFSubType').set('value', 'Printer');  
  7.     } 
  8.   });
GeoffreyWest
Occasional Contributor III

Thank you Robert.   

0 Kudos
GeoffreyWest
Occasional Contributor III

I am getting back around to this, I am fairly novice with JavaScript.  The code snippet above is ideal for my application, if E-WASTE is chosen in cbRequestType then cbEWASTE populates with different types of e-waste commodites.  See my code below; what could be wrong with this that it does not pass to the combo box?  I have a function which populates the e-waste combo box from the feature layer, should this be removed?

   (dijit.byId("cbRequestType").on('change', function(MFValue) {

    if (MFValue == 'E-WASTE') {

        dijit.byID("cbEWASTE").set('value', 'Copy Machine');

    }

    else if (MFValue == '...') {

        dijit.by.ID('cbEWASTE').set('value', 'Printer');

    }

});  

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Geoffery,

   So are you trying to set the Combobox selected value (i.e. the CB is already populated with values and you are just trying to set the selected value of the CB)?

GeoffreyWest
Occasional Contributor III

Yes, so if cbRequestType is set with E-WASTE then cbSubType is to populate with e-waste types.    

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Geoffery,

  I am still unsure, based on your responses if the cbRequestType combobox ALREADY has the appropriate choices and you just want to select one certain value from it, or do you need to populate the CB with specific values.

I have a function which populates the e-waste combo box from the feature layer, should this be removed?

This makes it sound like you already have the desired values as part of this combobox, but I am not sure this is the case.

GeoffreyWest
Occasional Contributor III

Thank you for your help Robert. cbRequestType has the values which are to be passed to the next cb, which I will hardcode and not pass from the feature layer.

So again, if I select E-WASTE from cbRequestType, I'd like cbEWASTE to populate with e-waste types such as copier, scanner, pc, etc.  But if WHITE GOODS is selected from cbRequestType I would like my cbEWASTE to populate with white goods types, such as refrigerators, metals, etc.

cbRequestType populates from my feature layer, but based on the script, it would be easier to hard code the statement which links cbRequestType to cbEWASTE.

So I would like to pass a function which populates cbEWASTE on change of cbRequestType...I will have many other fields which follow the same format, so e-waste is just an example...    

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Geoffery,

  I was so confused by your desired workflow I did not see the errors in your code.

dijit.byID is suppose to be dijit.byId (notice capital I only) then in your else you have dijit.by.ID...

Correct code:

          (dijit.byId("cbRequestType")).on('change',function(MFValue){

            if (MFValue == 'E-WASTE') {

              dijit.byId("cbEWASTE").set('value', 'Copy Machine');

            } else if (MFValue == '...') {

              dijit.byId('cbEWASTE').set('value', 'Printer');

            }

          });

GeoffreyWest
Occasional Contributor III

Not really sure what's incorrect then.  I am receiving the error; Uncaught ReferenceError: dijit is not defined serviceRequest.js:1638(anonymous function).

0 Kudos