lundi 10 octobre 2016

What is the correct use for If OR that statement [duplicate]

This question already has an answer here:

I am having an issue using the if OR that statement in jquery.

For the below code I have a jquery dialog showing if there are certain names that are selected in the autocomplete field. What is happening is that, using || is causing ANY selection to show the dialog. I only want it to show for certain selections.

if($(this).val() == "Paul" || "John" || "Mark") {
$( "#multiplesections" ).dialog();  
}

What is happening is that if I select Luke, the dialog is also popping up.

I have been successful with using the following but feel like it is too long - considering there are over 30 names from a 100 that I need to have the dialog show:

if($(this).val() == "Paul") {
$( "#multiplesections" ).dialog();  
}
if($(this).val() == "John") {
$( "#multiplesections" ).dialog();
}
if($(this).val() == "Mark") {
$( "#multiplesections" ).dialog();
}

Aucun commentaire:

Enregistrer un commentaire