Solved

javascript doesnt work in IE 9 and IE 10

Posted on 2013-05-12
9
1,065 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 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

930 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

14 Experts available now in Live!

Get 1:1 Help Now