I can't read BOOLEAN values in my webpage
I am trying to read BOOLEAN tags in my webpage, and they come in just fine. The problem is when I try to change the way I write the value of the tag to screen so that something meaningful is displayed instead... for example:
If a BOOLEAN = True, then write "Online"
If a BOOLEAN = False, then write "Offline"When I do this, the output always shows "Offline".
The problem is most likely the data type that is being handed back to you. If your code uses an instruction similar to the following:
callIDSprinklers = easyDAClient1.ReadItem("127.0.0.1", "SWToolbox.TOPServer.V5", "Channel_1.Device_1.Tag_1");
... then the problem is most likely that your boolean value is coming back in string format, i.e. True = "True" and False = "False"
Therefore, if when comparing the value of the tag you are:
if (result.value == true || result.value == 1 || result.value == -1)
{
document.getElementById("editSprinklers").value = "Online";
}
else
{
document.getElementById("editSprinklers").value = "Offline";
}
You should replace with:
if (result.value == "true" || result.value == "True")
{
document.getElementById("editSprinklers").value = "Online";
}
else
{
document.getElementById("editSprinklers").value = "Offline";
}