If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] Going Nutz here with .getElementById

Ok, picture this...

Table

Each cell of the table has an id tag that has been manually set.

I use document.getElementById( targetID ); to hook the cell.

targetID is generated from a function that I have tried with lots of variants and it returns an ID within the range of 0,1 to 6,5 (bit like x and y cords. This part I know works but the problems start with trying to apply properties to the hooked element.

I have used alert( targetID ) to see that the resulting bloc calculation is within a specific range and it returns every time a reference in the table, today will produce x4_y4 and that reference exists, however both FireFox and Chrome result in an error as previously stated. Tomorrow will result in x5_y4.

I am really too tired to try figuring out the issue and if anyone figures it out, let me know.

G'Night folks.

--> JavaScript Frameworks like JQuery, Angular, Node <--
... and please remember to wrap code with forum BBCode tags:- [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]If you can't think outside the box, you will be trapped forever with no escape...

Obviously the error is hidden somewhere in the "calc_block" function because you got "Uncaught TypeError: Cannot read property 'style' of null" which indicates unknown or missing value. So JavaScript cannot access your "t" object and set its properties because "t" object doesn't exists (is not properly referenced).

Also when defining a variable that is meant to latter hold an object, it is advisable to initialize the variable to null as opposed to anything else. That way you can explicitly check for the value null to determine if the variable has been filled with an object reference at a latter time.

It would help to see the entire page. I agree with tech_soul8 that the value of 't' is probably null because the call to getElementById() failed. The first thing I'd suggest would be to check that you use the same code to generate the value of the 'id' attribute for your <td> element is identical to the code you use for the calc_block() function. If it is identical, checking 'View Source' on the live page might uncover a stray character being inserted in the 'id' value.

Note, too, that 'innerText' is not fully cross-browser compliant. You might want to use 'innerHTML' instead.