473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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?
Jun 11 '19 #1
20 1255
gits
5,390 Expert Mod 4TB
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.
Jun 11 '19 #2
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?
Jun 11 '19 #3
gits
5,390 Expert Mod 4TB
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.
Jun 11 '19 #4
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?
Jun 11 '19 #5
gits
5,390 Expert Mod 4TB
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.
Jun 11 '19 #6
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
Jun 11 '19 #7
gits
5,390 Expert Mod 4TB
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.
Jun 11 '19 #8
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?
Jun 12 '19 #9
gits
5,390 Expert Mod 4TB
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].
Jun 12 '19 #10
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
Jun 12 '19 #11
gits
5,390 Expert Mod 4TB
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
Jun 12 '19 #12
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.
Jun 12 '19 #13
gits
5,390 Expert Mod 4TB
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.
Jun 12 '19 #14
Okay great idea. Thanks.
Jun 12 '19 #15
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
Jun 17 '19 #16
gits
5,390 Expert Mod 4TB
probably you should use:

Expand|Select|Wrap|Line Numbers
  1. dropdown[dropdown.selectedIndex].value
Jun 17 '19 #17
I have tried
Expand|Select|Wrap|Line Numbers
  1. filterDropDown = dropdown[dropdown.selectedIndex].value;
but this is not working too
Jun 17 '19 #18
gits
5,390 Expert Mod 4TB
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.
Jun 17 '19 #19
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
Jun 17 '19 #20
gits
5,390 Expert Mod 4TB
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.
Jun 17 '19 #21

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

Similar topics

6
by: John Ramsden | last post by:
.... when the id 'junk' doesn't exist anywhere in the document, instead of returning 'object'?! I am using Javascript for a drop-down menu, slightly adapted from one by Angus Turnbull (see...
1
by: Johm | last post by:
I am trying to append a property to the object Validation rule in the field branch1 of the table products.I then get the message "Cannot append. An object with the same name exists in the...
1
by: Owen | last post by:
Hi, I have a custom control which comprises a label and a text input box. I add one of these to my web form and call it "MyTextControl". I am trying to havea RegularExpressionValidator which...
5
by: fred | last post by:
With a Class is there any difference between a readonly property and function besides having to use Get/End Get. Are there any performance/resource advantages for either. Thanks Fred
1
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. ...
14
by: avsharath | last post by:
In "Bjarne Stroustrup's C++ Style and Technique FAQ" at: http://www.research.att.com/~bs/bs_faq2.html#evaluation-order for the statement: f(v,i++); he says that "the result is undefined...
1
by: tomjbr.32022025 | last post by:
I have started looking at the nhibernate framework, but do not really like the string based API which makes it impossible to use automatic refactoring of a property name without the risk of getting...
3
by: avanti | last post by:
HI, I have a HyperLink in my code. It has a OnClick function defined. I am trying to access the text property of the HyperLink in my JavaScript function. ...
3
by: 00steve | last post by:
Hi, I am attempting to create a script in which object A contains an array of "objectb" objects. An overview of the code is posted below. When I attempt to access "myObjArr" array like this: ...
1
by: xsd | last post by:
Hello 2 all, I have the following problem in finding the property value from the loaded assembly (control). I am the following setup: Language: C# OS: WinXP MVS 2005/2008 .NET 2.0 - 3.5
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.