I'm new to javascript and I'm trying to build a script within html that creates a variable x, and then writes it to a cell in a table. This is what I've come up with, but it doesn't work.
<table border="1">
<tr>
<td>Text</td>
<td id="xx"></td>
<td><button type="button" onclick="x()">Check</button></td>
</tr>
</table>
<script>
function x() {
var x = idec.device_read("D", 0901, 0, 0);
}
document.getElementById("xx").innerHTML = x;
</script>
The idea is that when you click the button, the result from var x can be viewed in the cell. But as it didn't work, I added the following to the script
var y = 5;
right at the top
Then I added
<p>
<script>
document.write(x + "<br>");
document.write(y);
</script>
</p>
Which in theory should of at least added a five after the table... or not? Because no five appeared...
Part of the problem could be that I've got the
var x = idec.device_read("D", 0901, 0, 0);
part wrong as I've no way of properly verifying that.