I have run into this problem again and now really need to know how to correctly write this array.
I have a drop-box that, based on the value selected, will display a particular field-set(s) via the ID of the field-set.
In some cases, two different values from the drop-box may call the same field-sets. So for example, if I choose banners, several field-sets will be displayed, if I choose Homepage Updates, the same field-sets would be displayed. So I want my array to basically be>> if the value selected in project type drop-box equals Banners or Homepage Updates, show the specified field-sets. The problem is, only the first option works. In this case Banners. When I select Homepage Updates, nothing is displayed.
Does anyone know who to write this array correctly? I have a ton of types that I have to code and the array is the clearest way to write it, but I can’t get past this hurdle. Help please. A portion of the array is below.
var projectTypes = new Array (
{id : '660' , value:('Banners' ||'Homepage Updates')},
{id : '659' , value:('Banners' || 'Homepage Updates')},
{id : '661' , value:'Banners'},
{id : '662' , value:'Banners'},
{id : '663' , value:'Banners'},
{id : '668' , value:'Redirect'},
{id : '229' , value:'Affiliates'},
{id : '236' , value:'Affiliates'},
{id : '242' , value:'Affiliates'},
{id : '250' , value:'Affiliates'},
{id : '251' , value:'Resources'},
{id : '375' , value:'Resources'},
{id : '376' , value:'Resources'},
{id : '377' , value:'Ads'},
{id : '237' , value:'Ads'}
);
Firstly, your expression
('Banners' ||'Homepage Updates')will always be evaluated to'Banners'.The logical operator OR ( written as
||) is evaluated as :Since the first expression’s argument is a String that is not empty, it is automatically converted to a
truevalue (because of the automatic type-conversion.In your case, I suggest You use an array of possible values to for your objects.
This way, you can choose the appropriate one:
If I understand correctly and you want to access some ids based on a value, you could organize your objects like this :