Uncaught SyntaxError: Identifier 'txt' has already been declared

Hello guys,
In the cell of a table I want to display instead of a letter a character but in my testprogram I have problems to display correct my output.
When I start the program it works. But when I change the x and y nothing happen...
In the developer tools from the browser (f12) i found the error: "Uncaught SyntaxError: Identifier 'txt' has already been declared".
I don't have other variables with the same name.
What did I do wrong?
Thank you so much in advance!

<!--<div ng-bind-html="msg.payload"></div>-->

<style>
        #table-test td {
            width: 40px;
            height: 40px;
        }
</style>
    
<table id="table-test">
    
        <tr>
            <td>a</td>
            <td>b</td>
            <td>c</td>
            <td>d</td>
        </tr>
        
        <tr>
            <td>e</td>
            <td>f</td>
            <td>g</td>
            <td>h</td>
        </tr>
       
        <tr>
            <td>i</td>
            <td>j</td>
            <td>k</td>
            <td>l</td>
        </tr>
</table>


<script>
    cellX = 0, cellY = 0; 
    var theTable = document.getElementById('table-test'), 
    theCell = theTable.rows[cellY].cells[cellX],
    wCell = theCell.offsetWidth, hCell = theCell.offsetHeight;
    theCell.style.position = 'relative';
    theCell.innerHTML = '';
    let txt = document.createTextNode('**');
    theCell.appendChild(txt);
</script>

when you call it the second time - the let txt= is already declared from the first time so it causes the error. You notice that you don't declare let cellX= or any of the other variables the same way.

@dceejay:
Thank you so much for your fast help.
Now I leave out the comand "let" on the variable txt and it works.
How I access to msg object in javascript? I found this but I' m not an excpert and so I have difficult to understand it... I get allways the error: "msg is not defined"
How i have to write the code to access to the msg object?
Thanks for our help!
For example I have this testcode:

<script>
var a = msg.payload.a[1].test;
switch (a){
  case 1:
        text:"1";
        break;
case 2:
       text:"2";
      break;
}
</script>

Remember that Dashboard uses Angular so the msg object is buried inside the Angular environment.

I wrote a blog post about it a long time ago:

@TotallyInformation:
Thank you for your help.
For me is AngularJS new :woozy_face: but I will try to understand your sourcecode on your blog and apply it to my testcode. :cowboy_hat_face:

1 Like