javascript doesnt work in IE 9 and IE 10

I have posted a question few weeks back

i t was resolved then but now I found that the same script doesn't work in IE9 and IE10. It doesnt work in Chrome and Firefox either but that's secondary. I would like it to work in IE first. Is there a difference in reading parentElement in IE9/10? Please help!
Who is Participating?
Kim WalkerConnect With a Mentor Web Programmer/TechnicianCommented:
You may want to check for the nodeType of childNodes[0]. I believe an input element would return a nodeType of 1 which is the nodeType of an element. Standards requires that any whitespace in the HTML code generate an empty text node in the node list which returns a node type of 3. Earlier versions of IE ignores the white space nodes. Perhaps something like this:
var node = row.cells[3].firstChild;
while (node && node.nodeType == 3) {
     node = node.nextSibling;
node.value = ...

Open in new window

Kim WalkerWeb Programmer/TechnicianCommented:
Use parentNode instead of parentElement. See parentNode reference.
Angel02Author Commented:
I tried it. Replaced all parentElement with parentNode everywhere in js. But it did not work. Please advise if I can try anything else. Thanks!
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Kim WalkerWeb Programmer/TechnicianCommented:
What is the error? Can you post a link to the page so that I can troubleshoot?
Kim WalkerWeb Programmer/TechnicianCommented:
Looking at your old question, it's hard to determine exactly what you ended up with. One thing that I noticed from the last comment you posted with code is that you have a case specific error. It should be childNodes with a capital N where you now have childnodes.
RobConnect With a Mentor Owner (Aidellio)Commented:
Have you used the developer tools to see what errors are being reported?  
Press F12 when you open IE to open the tools.  Go back to the browser and load your page.  Look in the console section of the tools for any errors and post back here with your results.
Angel02Author Commented:
Thanks for the reply. Here is the problem and the cause.

I have a datagrid with dropdowns and textboxes. When the value in dropdown changes, i need to change the value in the textbox. Below is my code:

function discTypeChange(elmCurrent)
                  var currVal = new String(elmCurrent.value);
                        var row = elmCurrent.parentNode.parentNode;
                        var cellUnit = row.cells[4];
                        var cellPrice = row.cells[7];
                              cellUnit.innerHTML = "USD";
                              row.cells[3].childNodes[0].value = cellPrice.innerHTML;
                              cellUnit.innerHTML = "%";
                              row.cells[3].childNodes[0].value = "0";

This code works perfectly in IE8 but not in IE10, Chrome and Firefox.
With tagit's sugegstion, I debugged the script and found that if I replace childNodes[0] with childNodes[1], it works in IE10, Chrome and Firefox and not in IE8.

Is this normal behavior in such scenerios? What is the best way to resolve this?

(1) Should I obtain the clientID of the browser and user childNodes[0] or childNodes[1] suitably?
(2) should I check if the value of childNodes[0] is null and if yes use childNodes[1]?

Please advise if there are better solutions. Thanks again!
Angel02Author Commented:
You are right. IE 10 returned nodeType = 3 and IE8 returned nodeType = 1.
So I am checking the nodeType and obtaining childNodes[1]] or childNodes[0] respectively.

You mentioned whitespaces in HTMl code. Can those be avoided? I don't find any whitespaces in my HTML code. I looked through the <asp:datagrid> and it looks fine. Please advise.
Kim WalkerWeb Programmer/TechnicianCommented:
A return between elements or a tab to indent your code for clarity is considered white space. I guess the only way to avoid it would be to run your entire html document in one single line of code. It would be hard to debug, though.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.