I'm new to javascript...I'm getting 'parentNode' is null or not an object error in the following code - for (var ci=0;ci<headerLink.parentNode.childNodes.length;ci++) {
-
if (headerLink.parentNode.childNodes[ci].tagName && headerLink.parentNode.childNodes[ci].tagName.toLowerCase() == 'span') span = headerLink.parentNode.childNodes[ci];
-
}
can anybody tell me what is the error ?
2 8096 gits 5,390
Expert Mod 4TB
hi ...
welcome to TSDN ...
probably headerLink is not a valid node ... so to be sure we need to see more of your code especially the code where headerLink gets assigned a node-reference ...
kind regards
thank you for your reply gits, I hadn't logged in for quite a while, should I include the enitre script file? anyways, I have included it!! - //BEGIN
-
addEvent(window, "load", sortables_init);
-
-
//Common Variables
-
var SORT_COLUMN_INDEX;
-
var oldRows = new Array();
-
-
//=================================================================================
-
// This function will find all tables with class sortable and make them sortable
-
//=================================================================================
-
function sortables_init() {
-
// Find all tables with class sortable and make them sortable
-
if (!document.getElementsByTagName) return;
-
tbls = document.getElementsByTagName("table");
-
var sortable =0;
-
for (ti=0;ti<tbls.length;ti++)
-
{
-
thisTbl = tbls[ti];
-
if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id))
-
{
-
sortable =1;
-
var headerTable = eval("document.all."+thisTbl.id+"header"); //To get the header table
-
ts_makeSortable(headerTable,thisTbl); // Pass the header table and detail table
-
-
}
-
}
-
// get sortcolumn and sortarrow
-
// append sortcolumn to sa to get the column
-
if((document.forms[0].hidSortArrow.value == 'null') || (document.forms[0].hidSortArrow.value == "")){
-
document.forms[0].hidSortArrow.value="up";
-
document.forms[0].hidSortColumn.value=0;
-
}
-
-
var curValue = document.forms[0].hidSortArrow.value;
-
if(sortable ==1){
-
if (document.all.list_table.rows.length >1) {
-
ts_resortTable(eval('document.all.sa'+document.forms[0].hidSortColumn.value), document.all.list_table);
-
if(curValue == "up"){
-
ts_resortTable(eval('document.all.sa'+document.forms[0].hidSortColumn.value), document.all.list_table);
-
}
-
}
-
}
-
-
}
-
//=================================================================================
-
// This function will make the tables sortable
-
//=================================================================================
-
-
function ts_makeSortable(headerTable, detailTable) {
-
if (detailTable.rows.length<=1) return;
-
if (headerTable.rows && headerTable.rows.length > 0)
-
{
-
var firstRow = headerTable.rows[0];
-
}
-
-
if (!firstRow) return;
-
-
// We have a first row: assume it's the header, and make its contents clickable links
-
for (var i=0;i<firstRow.cells.length;i++)
-
{
-
var cell = firstRow.cells[i];
-
var txt = ts_getInnerText(cell);
-
//Set the hyperlink for the cell that contains the heading
-
cell.innerHTML = '<h1> <a href="#" id=sa'+i+' onclick="ts_resortTable(this,document.all.'+detailTable.id+');return false;">'+txt+'</a><span class="sortarrow"></span></h1>';
-
}
-
}
-
//=================================================================================
-
//To get the inner text within a cell
-
//=================================================================================
-
function ts_getInnerText(el){
-
if (typeof el == "string") return el;
-
if (typeof el == "undefined") { return el };
-
if (el.innerText) return el.innerText; //Not needed but it is faster
-
var str = "";
-
-
var cs = el.childNodes;
-
var l = cs.length;
-
for (var i = 0; i < l; i++) {
-
switch (cs[i].nodeType) {
-
case 1: //ELEMENT_NODE
-
str += ts_getInnerText(cs[i]);
-
break;
-
case 3: //TEXT_NODE
-
str += cs[i].nodeValue;
-
break;
-
}
-
}
-
return str;
-
}
-
//=================================================================================
-
//To perform the sorting when clicked on the header links
-
//=================================================================================
-
function ts_resortTable(headerLink,detailTable) {
-
// get the span
-
var span;
-
for (var ci=0;ci<headerLink.parentNode.childNodes.length;ci++) {
-
if (headerLink.parentNode.childNodes[ci].tagName && headerLink.parentNode.childNodes[ci].tagName.toLowerCase() == 'span') span = headerLink.parentNode.childNodes[ci];
-
}
-
var spantext = ts_getInnerText(span);
-
//var tcolumn = headerLink.parentNode.parentNode;
-
-
var column = headerLink.parentNode.parentNode.cellIndex; //Obtain the cell index of the cell whose hyperlink was clicked.
-
var table = detailTable;
-
-
-
-
document.forms[0].hidSortColumn.value=column;
-
-
// Work out a type for the column
-
if (table.rows.length <= 1) return;
-
var itm = ts_getInnerText(table.rows[1].cells[column]);
-
-
sortfn = ts_sort_caseinsensitive;
-
if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
-
if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
-
if (itm.match(/^\w\w\w\s\d\d[\/-]\d\d[\/-]\d\d\s\d\d\:\d\d\s\w\w$/)) sortfn = ts_sort_date;
-
if (itm.match(/^\w\w\w\s\d\d[\/-]\d\d[\/-]\d\d\s\d\d\:\d\d\s\w\w\s$/)) sortfn = ts_sort_date;
-
if (itm.match(/^[?$]/)) sortfn = ts_sort_currency;
-
if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
-
-
SORT_COLUMN_INDEX = column;
-
-
if(oldRows.length <= 0){
-
for (j=1;j<table.rows.length;j++)
-
{ oldRows[j-1] = table.rows[j]; }
-
}
-
-
var newRows = new Array();
-
for(i=0;i<oldRows.length;i++)
-
newRows[i] = oldRows[i];
-
-
newRows.sort(sortfn);
-
if (span.getAttribute("sortdir") == null)
-
span.setAttribute('sortdir','up');
-
-
if (span.getAttribute("sortdir") == 'up') {
-
ARROW = ' <img src="img/down_arrow.jpg" align="center" border="0">';
-
newRows.reverse();
-
span.setAttribute('sortdir','down');
-
-
} else {
-
ARROW = ' <img src="img/up_arrow.jpg" align="center" border="0">';
-
newRows.sort(sortfn);
-
span.setAttribute('sortdir','up');
-
}
-
-
// ARROW=tcolumn.innerHTML;
-
-
document.forms[0].hidSortArrow.value=span.getAttribute("sortdir");
-
-
-
// We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
-
// don't do sortbottom rows
-
for (i=0;i<newRows.length;i++) { if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) table.tBodies[0].appendChild(newRows[i]);}
-
// do sortbottom rows only
-
for (i=0;i<newRows.length;i++) { if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) table.tBodies[0].appendChild(newRows[i]);}
-
-
// Delete any other arrows that may be showing
-
var allspans = document.getElementsByTagName("span");
-
for (var ci=0;ci<allspans.length;ci++) {
-
if (allspans[ci].className == 'sortarrow') {
-
if (getParent(allspans[ci],"table") == getParent(headerLink,"table")) { // in the same table as us?
-
allspans[ci].innerHTML = ' ';
-
}
-
}
-
}
-
-
// applying different back ground colors to alternate rows
-
for (j=1;j<table.rows.length;j++)
-
{
-
if(j%2 == 0){
-
table.rows[j].bgColor = "#FEFEF5";
-
} else {
-
table.rows[j].bgColor = "#BCD2EE";
-
}
-
}
-
-
span.innerHTML = ARROW;
-
}
-
//=================================================================================
-
//To get the parent node
-
//=================================================================================
-
function getParent(el, pTagName) {
-
if (el == null) return null;
-
else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) // Gecko bug, supposed to be uppercase
-
return el;
-
else
-
return getParent(el.parentNode, pTagName);
-
}
-
//=================================================================================
-
//To do the sorting based on date
-
//=================================================================================
-
function ts_sort_date(a,b) {
-
// y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
-
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
-
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
-
-
if (aa.length >= 21 ) {
-
dt1 = aa.substr(10,2)+aa.substr(4,2)+aa.substr(7,2)+aa.substr(19,2)+aa.substr(13,2)+aa.substr(16,2) ;
-
}else if (aa.length == 10) {
-
dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
-
} else {
-
yr = aa.substr(6,2);
-
if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
-
dt1 = yr+aa.substr(3,2)+aa.substr(0,2);
-
}
-
if (bb.length >= 21) {
-
dt2 = bb.substr(10,2)+bb.substr(4,2)+bb.substr(7,2)+bb.substr(19,2)+ bb.substr(13,2)+bb.substr(16,2);
-
}else if (bb.length == 10) {
-
dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
-
} else {
-
yr = bb.substr(6,2);
-
if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
-
dt2 = yr+bb.substr(3,2)+bb.substr(0,2);
-
}
-
-
if (dt1==dt2) return 0;
-
if (dt1<dt2 ) return -1;
-
-
return 1;
-
}
-
//=================================================================================
-
//To sort based on currency
-
//=================================================================================
-
function ts_sort_currency(a,b) {
-
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
-
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
-
return parseFloat(aa) - parseFloat(bb);
-
}
-
//=================================================================================
-
//To sort numeric values
-
////=================================================================================
-
function ts_sort_numeric(a,b) {
-
aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
-
if (isNaN(aa)) aa = 0;
-
bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX]));
-
if (isNaN(bb)) bb = 0;
-
return aa-bb;
-
}
-
//=================================================================================
-
//To sort based on caseinsensitive
-
//=================================================================================
-
function ts_sort_caseinsensitive(a,b) {
-
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
-
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
-
if (aa==bb) return 0;
-
if (aa<bb) return -1;
-
return 1;
-
}
-
//=================================================================================
-
//To sort on a default column
-
//=================================================================================
-
function ts_sort_default(a,b) {
-
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
-
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
-
if (aa==bb) return 0;
-
if (aa<bb) return -1;
-
return 1;
-
}
-
//=================================================================================
-
//The function is called when the page is loaded
-
//=================================================================================
-
function addEvent(elm, evType, fn, useCapture)
-
// addEvent and removeEvent
-
// cross-browser event handling for IE5+, NS6 and Mozilla
-
-
{
-
if (elm.addEventListener){
-
elm.addEventListener(evType, fn, useCapture);
-
return true;
-
} else if (elm.attachEvent){
-
var r = elm.attachEvent("on"+evType, fn);
-
return r;
-
} else {
-
alert("Handler could not be removed");
-
}
-
}
-
//=================================================================================
-
//The function is called when the page is loaded
-
//=================================================================================
-
function doAlert() {
-
alert("ContextPath is: " + context_path);
-
}
-
//END
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michael Hill |
last post by:
I am trying to get all the "polyline" tags and then find the parent node
above it so I can transform it.
var poly = svgDocument.getElementsByTagName("polyline");
for ( var i=0; i < poly.length;...
|
by: JoostV |
last post by:
However, I am wondering if I can make the creation of my object depend
on the name of the parent node DURING parsing (or even the name of the
grandparent node)?? In other words, how can I do...
|
by: anupamjain |
last post by:
An interesting thing is happening. My table doesnt have 'TBody', but
the elem.parentNode.tagName is returning 'TBody' where elem refers to
the 'tr' tag.
Shouldnt it be returning 'table' ?
...
|
by: yawnmoth |
last post by:
Given an element ID, is there a way to figure out what index one would
need to use in the parentNode's childNodes array to get at that
element?
For example...
<body>
<div id="parent">
<div...
|
by: DanielLinn |
last post by:
I'm getting an error in IE 6.0.2800 that says "Error: Not implemented."
when I try to get a parent. Does it whether or not 'compatibility
mode' is on.
Here's my code:
<!DOCTYPE html PUBLIC...
|
by: amattie |
last post by:
Anyone know what the specific difference is between the offsetParent
and parentNode properties of a DOM element are?
Mozilla's docs on the DOM element...
|
by: webdeveloper |
last post by:
Without showing any code, I thought maybe somebody already knows what
the error message in the title generally means?
But in short, a menu is supposed to display by setting its inline style...
|
by: Michael C |
last post by:
If we have something like this
object x = null;
MessageBox.Show(x.ToString())
we get an error. That kindof makes sense but there is no reason the
behaviour couldn't be to return an empty...
|
by: =?Utf-8?B?R3JlZw==?= |
last post by:
I have the following three files.
1. Users.aspx is a webpage that uses the <asp:ObjectDataSourcecontrol to
populate a simple <asp:ListBoxcontrol.
2. The UserDetails.cs file creates a Namespace...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |