Strange javascript issue if statement test = true but won't execute?
In this click handler code:
$('#save').click(function () {
if (overAllStatus == 'red') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleRed.png" width="20" height="20"></a>';
}
else if (overAllStatus == "yellow") {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleYellow.png" width="20" height="20"></a>';
console.log('Over all status is yellow.');
}
else if (overAllStatus == 'greenR') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleGreenHollow.png" width="20" height="20"></a>';
}
else if (overAllStatus == 'greenN') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleGreen.png" width="20" height="20"></a>';
}
comments = $('#comments').val();
$("body").trigger(esc);
$("#save1").trigger('click');
redListSize = 0;
yellowListSize = 0;
console.log("save clicked");
});
when the value of the variable overAllStatus
is yellow
, as was checked in the JS console and I see this in the console before I hit the save button:
> overAllStatus
"yellow"
> overAllStatus == 'yellow'
true
I only see "save clicked" printed to the console. It seems that the code in test state is (overAllStatus == "yellow")
not executing. I do not understand why.
+3
user3914536
source
to share
1 answer
try replacing the code with this code and see what meaning "overAllStatus" has in your 'click' callback
$('#save').click(function () {
console.log("overAllStatus", overAllStatus); //use this to check the value of overAllStatus
if (overAllStatus == 'red') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleRed.png" width="20" height="20"></a>';
}
else if (overAllStatus == "yellow") {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleYellow.png" width="20" height="20"></a>';
console.log('Over all status is yellow.');
}
else if (overAllStatus == 'greenR') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleGreenHollow.png" width="20" height="20"></a>';
}
else if (overAllStatus == 'greenN') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleGreen.png" width="20" height="20"></a>';
}
comments = $('#comments').val();
$("body").trigger(esc);
$("#save1").trigger('click');
redListSize = 0;
yellowListSize = 0;
console.log("save clicked");
});
+3
source to share