I'm trying to stop execution of Javascript event handler when some condition is satisfied, and my code looks like this:
$(".save").click(function (event) {
$(".loader").fadeIn(300);
var statusValue = $("#status").val();
console.log(statusValue);
if (statusValue == null || statusValue == '') {
$("#status").css({
"border-color": "red",
"border-width": "1px",
"border-style": "solid"
});
event.preventDefault();
console.log("NOT EXECUTED");
}
console.log("EXECUTED");
// .. some more code
}
When I check console I'm getting results like this:
null
null
NOT EXECUTED
EXECUTED
So I'm wondering how come?
If == null
condition is satisfied shouldn't event.preventDefault()
stop this .click
event from execution till end?
I'm trying to achieve, if nothing is selected in then prevent execution, my select looks like this:
<select class="form-control" id="status">
<option value="Done">Done</option>
<option value="Complited">Completed</option>
<option value="Cancel">Cancel</option>
</select>