By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,969 Members | 1,579 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,969 IT Pros & Developers. It's quick & easy.

The property of a undefined or null-link cannot be retrieved

P: 27
I am using JavaScript for filter some content of a dynamically built table. I have a problem while read the content of a cell of the table
I read the content in my JavaScript with

Expand|Select|Wrap|Line Numbers
  1. var rows = table.getElementsByTagName("tr");
  2. var row = rows[i];
  3. cells = row.getElementsByTagName("td");
  4. modelRange = cells[0];
  5. filter = modelRange.innerText; // or filter = modelRange.textContent
  6.  
My relevant xslt code is:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="logstore/plane/trigger">
  2.             <tr>
  3.                 <td align="center"><xsl:value-of select="../Name"/></td>
  4.                 <td align="center"><xsl:value-of select="date"/></td>
  5.                 <td align="center"><xsl:value-of select="date"/></td>
  6.                 <td><xsl:value-of select="test"/></td>
  7.             </tr>
  8.         </xsl:for-each>
  9.  
When I try to start my JavaScript via Internet Explorer 11 I do get the error: The property of a undefined or null-link cannot be retrieved. This is a problem of
Expand|Select|Wrap|Line Numbers
  1. filter = modelRange.innerText;
. How can I solve that problem?
1 Week Ago #1
Share this Question
Share on Google+
20 Replies


gits
Expert Mod 5K+
P: 5,268
look closely what it means - modelRange is either undefined or null - that means you obviously have a table row with no td-elements. as i mentioned in your other thread already - IE used to create tables a bit differently so i assume your script fails at the first row where the table has probably a thead-element and a row with th-elements instead of td-elements.
1 Week Ago #2

P: 27
I am using
Expand|Select|Wrap|Line Numbers
  1.  if (filterDropDown === "All" || !modelRange || (filterDropDown === modelRange.innerText)) {}
in my JavaScript. If I would not use it and just go through the rows with
Expand|Select|Wrap|Line Numbers
  1. for (var i = 0; i < rows.length; i++) {} 
it will not throw an error. The error only occurs by using
Expand|Select|Wrap|Line Numbers
  1. filterDropDown === modelRange.innerText
in the if-case.
If I use
Expand|Select|Wrap|Line Numbers
  1. if (i > 2 && modelRange.innerText){}
no error will occur. So it is a problem with "===". Is it possible that it has problems with string comparison?
1 Week Ago #3

gits
Expert Mod 5K+
P: 5,268
javascript has no problems with string comparisons if your condition would not be met then those values are in fact not identical.

those few lines that you throw up here don't show that it is as you think it would be. The first post you made show some code where the error message makes perfect sense in case modelRange is undefined/null - whereas that error message wouldnt make sense if the problem would come from that condition. so i think different issues getting mixed up here now.
1 Week Ago #4

P: 27
Okay so what exactly do you recommend to do? You write something like: your first table row has no td-elements. What does that mean? Should I change my th rows with td rows?
1 Week Ago #5

gits
Expert Mod 5K+
P: 5,268
no - what i think is that in IE only you have that issue as since IE always creates a thead when creating a table dynamically through javascript - as far as i remember at least. so you would just have to harden your code for that issue like (going back to your code here):

Expand|Select|Wrap|Line Numbers
  1. cells = row.getElementsByTagName("td");
  2.  
  3. if (!cells[0]) {
  4.  
  5.     // you have a row with no td elements here so interrupt
  6.     // your script here accordingly with skipping this row
  7.     // since you obviously want to rely on that td-cells
  8.     // in your next line
  9. }
for the other issue where your strings dont match - you will need to trace the values as javascript sees them - it might be invisible characters or such that dont let them match.
1 Week Ago #6

P: 27
I have just think about it. You are right. But usually I am using
Expand|Select|Wrap|Line Numbers
  1. if (drop_down_menu === "All" || !modelrange || (filter === modelrange.innerText)) {}
When I am using that, no error will occr. With
Expand|Select|Wrap|Line Numbers
  1. !modelrange
I am just asking if this is the header row. So my header row will stay and won't disappear. All other rows will disappear because that if-case will be false for all other rows. That just can be the comparison of drop_down_menu with "All" and filter with content of modelrange.
Can you confirm that?
Thanks
1 Week Ago #7

gits
Expert Mod 5K+
P: 5,268
as i said - i think its 2 different issues. the one with the undefined/null issue occured in your first post because of javascript tells you that it couldnt retrieve an innerText property from a non existing object. so basically the script was interrupted at that line.

if that error is avoided the script runs through the next lines - otherwise it just holds at an fatal error. so if it comes to that condition (i assume here that the condition is located after the above mentioned lines where the error occured) and the strings dont match - then the strings are in fact not matching or it could be that your drop_down_menu doesnt equal "All" already - i cant see so far how that is retrieved by your script.
1 Week Ago #8

P: 27
You said: that it couldnt retrieve an innerText property from a non existing object.
What do you mean with non existing object?
In my JavaScript I declare modelrange with
Expand|Select|Wrap|Line Numbers
  1. var modelrange;
and then just use
Expand|Select|Wrap|Line Numbers
  1. var filterDropDown === modelRange.innerText
. Then the error occurs but I have declared modelrange. It does not come out of anything.
If I use
Expand|Select|Wrap|Line Numbers
  1.  if (i > 2 && modelRange.innerText === rows[i - 1].getElementsByTagName("td")[0].innerText) {
it does not throw any error, but that is the same "modelRange.innerText". That is working. So how can JavaScript tells me on one side it could not retrieve an innerText property from a non existing object and on the other hand it is doing very well?
1 Week Ago #9

gits
Expert Mod 5K+
P: 5,268
then u didnt post the proper code in post 1 of this thread - because in that code the error comes from exactly not being able to retrieve innerText from that modelRange which is obviously set to undefined by not having a td-cell in cells[0].
1 Week Ago #10

P: 27
Okay if I use
Expand|Select|Wrap|Line Numbers
  1. if (drop_down_menu === "All" || !modelrange || (filter === modelrange.innerText)) {//show this row}
  2. else {//hide this row}
it hides all rows except my "th" rows. So the comparison is just false because no error occur right?
If I just use
Expand|Select|Wrap|Line Numbers
  1. if (filter === modelrange.innerText)
then it will throw an error because the first row is "th" and not "td" but as I use not only
Expand|Select|Wrap|Line Numbers
  1. filter === modelrange.innerText
but also
Expand|Select|Wrap|Line Numbers
  1. !modelrange //if this is the header row
, then the first header row will not be compare with modelrange.innerText but the second and all other "td" rows will be compared. So it's just a comparison problem if you see it like how I described isn't it? Thanks
1 Week Ago #11

gits
Expert Mod 5K+
P: 5,268
ye - if the code in the first post isnt used as it is posted before the comparison - then its the comparison failing - but you removed 2 conditions to test - thats what i said in my 2nd recent post - it can return false here:

Expand|Select|Wrap|Line Numbers
  1. drop_down_menu === "All"
and here:

Expand|Select|Wrap|Line Numbers
  1. filter === modelrange.innerText
1 Week Ago #12

P: 27
Okay yes thanks. Than I will try to fix the "comparison" problem. Do you have any idea what IE makes different to Firefox with innerText? My string I need to compare is e.g. "RB_123". So firefox can do this. If I use "textContent" instead of "innerText" it does work too on FF but not on IE.

PS: Sorry for the misunderstanding. I just thought I post as less as necessary. It just was too less.
1 Week Ago #13

gits
Expert Mod 5K+
P: 5,268
i am not aware of differences betweeen the browsers with textContent - but that doesnt mean there aren't such that i am just unaware of.

as far as i know IE was implementing innerText first while the other browsers had textContent - but both yield different results and since IE 9 textContent should be supported in IE as well - and as tested recently here - i didnt see it behave differently for a static table at least.

but this can be easyly checked by simply letting javascript write the values that it in fact sees to the console - so you can see what happens there.
1 Week Ago #14

P: 27
Okay great idea. Thanks.
1 Week Ago #15

P: 27
Hi. I have tried
Expand|Select|Wrap|Line Numbers
  1. console.log(filterDropDown)
to get the content of my selected items in the drop-down-menu. When I am using Firefox the content is correct. When I am using IE I do not get any content. The content is empty. So I think the problem is the Following:
Expand|Select|Wrap|Line Numbers
  1. dropdown = document.getElementById('modelRangeDropdown');
  2. filterDropDown = dropdown.value;
  3.  
I think there is a problem with ".value". How else can I get the actual value of my dropdown menu?
Thanks
3 Days Ago #16

gits
Expert Mod 5K+
P: 5,268
probably you should use:

Expand|Select|Wrap|Line Numbers
  1. dropdown[dropdown.selectedIndex].value
3 Days Ago #17

P: 27
I have tried
Expand|Select|Wrap|Line Numbers
  1. filterDropDown = dropdown[dropdown.selectedIndex].value;
but this is not working too
3 Days Ago #18

gits
Expert Mod 5K+
P: 5,268
hmmmm - may be going the full path like this works then?

Expand|Select|Wrap|Line Numbers
  1. dropdown.options[dropdown.selectedIndex].value
if not you would need to check if your options have actually values set.

PS: since it did look weird to me i just tested it on an IE11 now with a static list where the value properties are set - all 3 versions did work - so i guess the listoptions are missing the value-properties in your case somehow.
3 Days Ago #19

P: 27
I am now using
Expand|Select|Wrap|Line Numbers
  1. filterDropDown = dropdown.options[dropdown.selectedIndex].text;
This is working.
So I have to use text instead of value
3 Days Ago #20

gits
Expert Mod 5K+
P: 5,268
so in fact your listoptions have no value attribute then - as it turns out - in this case IE is doing it correctly from my point of view - since obviously other browsers just return the text in case no value attribute is present - thus leading to such confusion here. properties shouldn't be silently 'reused' by browsers. Even if i hate to have to say that in favor of IE now :)

to avoid that issue the best way would be to make sure in your code where the options are created - that you create and assign the value property.
3 Days Ago #21

Post your reply

Sign in to post your reply or Sign up for a free account.