Solved

javascript doesnt work in IE 9 and IE 10

Posted on 2013-05-12
9
1,060 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
  • 5
  • 3
9 Comments
 
LVL 21

Expert Comment

by:Kim Walker
Comment Utility
Use parentNode instead of parentElement. See parentNode reference.
0
 

Author Comment

by:Angel02
Comment Utility
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 21

Expert Comment

by:Kim Walker
Comment Utility
What is the error? Can you post a link to the page so that I can troubleshoot?
0
 
LVL 21

Expert Comment

by:Kim Walker
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 200 total points
Comment Utility
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
Comment Utility
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 21

Accepted Solution

by:
Kim Walker earned 300 total points
Comment Utility
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
Comment Utility
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 21

Expert Comment

by:Kim Walker
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now