How would I add another not equal (!=) value to this statement?
if ($(this).data("increase_priority1") && $(this).val() != 1)
I tried reversing the syntax at the beginning of the function which determines if it is equal, but that stopped it from removing items completely (including those not equaling 1)
if ($(this).data("increase_priority1") && $(this).val() != 1 && $(".complaint select").val() != "Too_small")
This function adds and/or remove values from “increase_priority1” when the user has selected both a complaint and ranked the importance level of the issue, and I need it to change the value (in this case what the complaint is) and importance level (i.e. increase_priority1) if either of those 2 fields changes. At the moment it only changes when the importance level changes.
The full function is:
var $increase_priority1 = $(".increase_priority1");
$('.ranking, .complaint select').dropkick({
change: function () {
var name = $(this)
.data("name"); //get priority name
if ($(".complaint select")
.val() === "Too_small" && $(this)
.val() == 1 && !$(this)
.data("increase_priority1")) {
//rank is 1, and not yet added to priority list
$("<option>", {
text: name,
val: name
})
.appendTo($increase_priority1);
$(this)
.data("increase_priority1", true); //flag as a priority item
}
if ($(this)
.data("increase_priority1") && $(this)
.val() != 1) {
//is in priority list, but now demoted
$("option[value=" + name + "]", $increase_priority1)
.remove();
$(this)
.removeData("increase_priority1"); //no longer a priority item
}
}
});
Fiddle which shows this in context: http://jsfiddle.net/chayacooper/vWLEn/132/
An OR-operation is true when at least one of the operands is true (possibly both!). Your statement should be:
||is the Javascript-syntax for an OR.This will run the
ifif.data("increase_priority1")is true and$(this).val() != 1or$(".complaint select").val() != "Too_small")is true.Note that the interpreter will stop if the first part of the
&&is false, that is to say: it will not even look at the second part. It is the same for the||, but the other way around, so if the first part of the||is true it will not look at the second part.