I need help changing the text and font color of my ASP.net label based on its content.
The label displays a percentage change, and I want negative numbers to be shown in green and positive numbers in red.
However, when I try to implement this, I keep encountering an error message saying "TypeError: document.getElementById(....) is null".
I understand that using window.onload is not the best practice, but I just wanted to test it quickly.
Could someone please point out what I'm doing wrong? I feel like I'm just going around in circles with this issue.
window.onload = fillDays;
function fillDays() {
var change = document.getElementById("<%=lblPercentageDifferenceToFillReqCurrentVsPreviousMonth %>").value;
if (change.indexOf(char) = '-') {
document.getElementById("<%=lblPercentageDifferenceToFillReqCurrentVsPreviousMonth %>").style.color = "green";
}
else {
document.getElementById("<%=lblPercentageDifferenceToFillReqCurrentVsPreviousMonth %>").style.color = "red";
}
console.log("fillDays")
};