-1

The code below is only returning the first if statement regardless of whether the var product_check is actually equal to the other else if conditions. Could someone point me in the right direction with this? I'm sure it has to be an easy fix...

var product_check = '<?php echo($productLine); ?>';

if (product_check === 'Blades' || 'Ceiling Tiles' || 'Clouds' || 'Partitions' || 'Panels') {
    jQuery('select#input_6_28 option').html('Acoustical Solutions');
} else if (product_check === 'Curva') {
    jQuery('select#input_6_28 option').html('Appliances');
} else if(product_check === 'Acrylic Resin Panels' || 'High Gloss Panels' || 'Super Matte Panels' || 'Modular Cork Wall Panels' || 'Reclaimed Hardwood') {
    jQuery('select#input_6_28 option').html('Architectural Panels');      
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
Seth Spivey
  • 347
  • 2
  • 4
  • 22
  • 3
    You can't check multiple values that way (`if (product_check === 'Blades' || 'Ceiling Tiles' `). You need to test each one individually (e.g. `if (product_check === 'Blades' || product_check === 'Ceiling Tiles' `). You could also create an array and use array functions to check against. – j08691 Jan 16 '18 at 21:54
  • 1
    Possible duplicate of [Check variable equality against a list of values](https://stackoverflow.com/questions/4728144/check-variable-equality-against-a-list-of-values) –  Jan 16 '18 at 21:55
  • 1
    You can also use a switch case. – Spoody Jan 16 '18 at 21:57
  • 1
    Why is this tagged PHP? (Not that the problem is that much different in PHP, but still...) – Don't Panic Jan 16 '18 at 22:01

1 Answers1

1

You need to check each one individually.

Try this:

var product_check = '<?php echo($productLine); ?>';

if (product_check === 'Blades' || product_check === 'Ceiling Tiles' || product_check === 'Clouds' || product_check === 'Partitions' || product_check === 'Panels') {

jQuery('select#input_6_28 option').html('Acoustical Solutions');

} else if (product_check === 'Curva') {

    jQuery('select#input_6_28 option').html('Appliances');

} else if(product_check === 'Acrylic Resin Panels' || product_check === 'High Gloss Panels' || 
product_check === 'Super Matte Panels' || product_check === 'Modular Cork Wall Panels' || product_check ==='Reclaimed Hardwood') {

    jQuery('select#input_6_28 option').html('Architectural Panels');
}

Using a switch block would be better.

Example:

switch (product_check) {
    case 'Curva':
        jQuery('select#input_6_28 option').html('Appliances');
        break;
    case 'Acrylic Resin Panels':
    case 'High Gloss Panels':
    case 'Super Matte Panels':
    case 'Modular Cork Wall Panels':
    case 'Reclaimed Hardwood':
        jQuery('select#input_6_28 option').html('Architectural Panels');
        break;
    default:
        jQuery('select#input_6_28 option').html('Acoustical Solutions');
        break;
}
Joshua
  • 426
  • 1
  • 10
  • 18