Reputation: 3066
I have the following javascript code
ws.onopen = function()
{
ws.send("running?");
};
ws.onmessage = function(evt)
{
var phrase = evt.data
console.log(phrase)
if(phrase == "1")
{
console.log(phrase)
document.getElementById("Button1").text="Pause";
document.getElementById("Label1").text="Running";
}
};
//fired when an error occurs during communication with websocket
ws.onerror = function (error)
{
document.getElementById("Label1").innerHTML = "Unknown"
document.getElementById("Button1").disabled = true;
};
function command()
{
var message = document.getElementById("Button1").value;
ws.send(message);
}
That goes along with the following HTML code
<html>
<script src="script_control.js" type="text/javascript">
</script>
<p>Script status: <label id="Label1"></label></p>
<button id="Button1" onclick="command()">Pause</button>
</html>
Each time the value of phrase outputs to console as "1"
signifying a text number one. However nothing changes on the page like it is supposed to even though the expression evaluates to try, why might this be happening?
Upvotes: 0
Views: 1368
Reputation: 104775
labels
and buttons
do not have a value
attribute, use textContent
:
document.getElementById("Button1").textContent="Pause";
document.getElementById("Label1").textContent="Running";
Upvotes: 6