Solved

javascript doesnt work in IE 9 and IE 10

Posted on 2013-05-12
9
1,092 Views
Last Modified: 2013-05-15
I have posted a question few weeks back
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28024181.html

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!
0
Comment
Question by:Angel02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 22

Expert Comment

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

Author Comment

by:Angel02
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!
0
 
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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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.
0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 200 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.
0
 

Author Comment

by:Angel02
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];
                        if(currVal==1){
                              cellUnit.innerHTML = "USD";
                              row.cells[3].childNodes[0].value = cellPrice.innerHTML;
                        }
                        else{
                              cellUnit.innerHTML = "%";
                              row.cells[3].childNodes[0].value = "0";
                        }
                        row.cells[3].childNodes[0].focus();
                  }

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!
0
 
LVL 22

Accepted Solution

by:
Kim Walker earned 300 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

0
 

Author Comment

by:Angel02
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.
0
 
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.
0

Featured Post

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.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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

630 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