...

View Full Version : document.getElementById("excelTable").rows[i].childNodes[0].innerText firefox



johnwhite11
01-16-2012, 07:08 PM
i have an onclick function, but after debuging i found that firefox and only firefox blocks at the line

" individualNames = names.childNodes[0].innerText; "
is there somthin im missing please help.

function searchForm()
{
var change = 0;
var searchValue = document.getElementById("searchValue").value.toLowerCase();
var count = document.getElementById("excelTable").rows.length;
var once = true;
myArray = new Array();

if(searchValue == ""){alert("Please enter a value"); return false}

for(i=0;i<=count;i++){

names = document.getElementById("excelTable").rows[i];

individualNames = names.childNodes[0].innerText;




//only by last name of the file coming in format == "LastName, FirstName"
lastName = individualNames.split(", ");
//only by last name

lowerCaseNames = lastName[0].toLowerCase();
names.style.backgroundColor = "#FFF";

if(lowerCaseNames.indexOf(searchValue) != -1)
{
names.style.backgroundColor = "#999";
//make the first result with the search apear on screen than stop after the first
if(once==true){document.getElementById("excelTable").rows[i].scrollIntoView(true); once=false;}


myArray[change] = document.getElementById("excelTable").rows[i];//fill a passing array to next function
change++;//make the array go to next slot

document.getElementById("nextButton").disabled = false;

document.getElementById("searchTitle").scrollIntoView(true);
}
}
}

felgall
01-16-2012, 07:58 PM
innerText is an Internet Explorer proprietary command. For cross browser support you should either use innerHTML or the appropriate DOM commands.

johnwhite11
01-16-2012, 08:13 PM
Wow easy fix, Thank you i didn't know that it was propreatary to IE but theoreticly if i had more children under that it would return the tags as well wich is unwanted if you want content, is the only solution is to parse everthing??

felgall
01-17-2012, 08:27 AM
Wow easy fix, Thank you i didn't know that it was propreatary to IE but theoreticly if i had more children under that it would return the tags as well wich is unwanted if you want content, is the only solution is to parse everthing??

JavaScript doesn't parse innerHTML content at all - it assumes that it is just plain text and ignores any tags in it. If you want JavaScript to be able to see the HTML tags within what you are adding you need to use the proper DOM commands to add them all separately as that is the only way that JavaScript will be able to reference the individual tags from its subsequent code.

As an example - if you use innerHTML to add a <div id='x'> tag to the page you cannot then reference it using getElementById('x') because JavaScript doesn't see that as a tag. You'd need to use createElement to create the tag, then add the id to it and then use appendChild to add it to the page in order to be able to reference the id in later JavaScript.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum