-5

I want to disable css when going through the if statement. But when I add another condition to the if statement the functions is not working.

Here is the function:

$(document).ready(function(){
  $("#exampleSelect1").change(function (){
    $('#form-zonwering').css('display','block');
    if($("#exampleSelect1 option:selected").val()!= "Greenline_Veranda" || "Profiline_Veranda"){
        $('#form-zonwering').css('display','none');}
  });
});

Thanks for your time!

Jari Rengeling
  • 326
  • 1
  • 15
  • 1
    can you clarify a bit more? I understood almost nothing from your description and example – N. Ivanov Apr 10 '18 at 09:47
  • https://www.tjvantoll.com/2013/03/14/better-ways-of-comparing-a-javascript-string-to-multiple-values/ – CBroe Apr 10 '18 at 09:49
  • This OR condition is not correct `$("#exampleSelect1 option:selected").val()!= "Greenline_Veranda" || "Profiline_Veranda")` – Niladri Apr 10 '18 at 09:49

1 Answers1

0

When placing multiple conditions in an if statement you need to duplicate them completely. Also note that you can call val() directly on the select element, not the chosen option.

var val = $("#exampleSelect1").val();
if (val != "Greenline_Veranda" && val != "Profiline_Veranda") {
    $('#form-zonwering').css('display', 'none');
}

However you should note that you can make the logic more succinct by using jQuery's toggle() method instead:

$("#exampleSelect1").change(function() {
  var val = $(this).val();
  $('#form-zonwering').toggle(val != 'Greenline_Veranda' && val != 'Profiline_Veranda');
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339