Go Premium for a chance to win a PS4. Enter to Win


javascript doesnt work in IE 9 and IE 10

Posted on 2013-05-12
Medium Priority
Last Modified: 2013-05-15
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!
Question by:Angel02
  • 5
  • 3
LVL 22

Expert Comment

by:Kim Walker
ID: 39161334
Use parentNode instead of parentElement. See parentNode reference.

Author Comment

ID: 39162443
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!
LVL 22

Expert Comment

by:Kim Walker
ID: 39162583
What is the error? Can you post a link to the page so that I can troubleshoot?
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 22

Expert Comment

by:Kim Walker
ID: 39162615
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.
LVL 43

Assisted Solution

Rob earned 800 total points
ID: 39163156
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.

Author Comment

ID: 39165390
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!
LVL 22

Accepted Solution

Kim Walker earned 1200 total points
ID: 39165504
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


Author Comment

ID: 39165816
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.
LVL 22

Expert Comment

by:Kim Walker
ID: 39165897
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.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question