Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-13-2010, 10:18 PM   PM User | #1
gizmo1650
Regular Coder

 
Join Date: Apr 2010
Posts: 163
Thanks: 3
Thanked 25 Times in 25 Posts
gizmo1650 is on a distinguished road
IE compatibility issue

EDIT: i think the problem was i had an html element named 'comment' so IE was getting confused when i made a js variable 'comment'
(don't use IE it is the worst browser)


i am in the process of debugging a website, it works wel in Google Chrome and firefox but not in IE
i am putting all the relevant code below.
this is in the head tag, and is the only JavaScript executed when the debugger show the error
Code:
function first_run(){
answer_state=document.getElementById('state');//set node for 'show_answer' function
answer_ab=document.getElementById('ab');//set node for 'show_answer' function
answer_capitol=document.getElementById('capitol');//set node for 'show_answer' function
answer_next=document.getElementById('next');
comment=document.getElementById('comment')//line marked with error
ui=document.getElementById('UI');//sets 'ui' to form location
score_right=document.getElementById('right');//returns null
score_wrong=document.getElementById('wrong');
score_right=score_wrong.previousElementSibling//score_right work around
score_show_ans=document.getElementById('show_ans');
runs above code on page load
Code:
<body onkeydown="if (event.keyCode == 13){check()}" onload="first_run()">
in body tag, node that erred line refers to.
Code:
<div id=comment>
</div>
the error message in IE's developer tools debugger is "Object doesn't support this property or method" States javascript.html, line 395 character 1"

i've done all of my coding in Chrome and have no expirence in IE's syntax, any ideas what the problem is?

Last edited by gizmo1650; 04-14-2010 at 01:36 AM..
gizmo1650 is offline   Reply With Quote
Old 04-13-2010, 11:18 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I think you have the wrong line.

That message would occur because you tried to do something like
Code:
   comment.framitz = 17;
or
   comment.zam();
MSIE's line numbers are often off by 1 or 2 in the error messages.

Can you show us the next 5 or 10 lines, right after the ones you showed?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 04-13-2010, 11:29 PM   PM User | #3
gizmo1650
Regular Coder

 
Join Date: Apr 2010
Posts: 163
Thanks: 3
Thanked 25 Times in 25 Posts
gizmo1650 is on a distinguished road
i added a few lines to the code
using the javascript console shows everything up to and including comment=document.getElementById('comment') works (putting in the variable name doesn't return undefined) but the following few lines, putting in the variable name returns undefined

Last edited by gizmo1650; 04-13-2010 at 11:34 PM..
gizmo1650 is offline   Reply With Quote
Old 04-14-2010, 12:03 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Almost surely this line:
Code:
score_right=score_wrong.previousElementSibling//score_right work around
If you look here:
http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx
and scan the properties, you will see previousSibling but no mention of previousElementSibling.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 04-14-2010, 01:00 AM   PM User | #5
gizmo1650
Regular Coder

 
Join Date: Apr 2010
Posts: 163
Thanks: 3
Thanked 25 Times in 25 Posts
gizmo1650 is on a distinguished road
changing to Previous sibling didn't help,
also this time i noticed when i ran the debugger thare was a balloon that popped up for a few seconds over the comment= line that said "breaking on JS runtime error-Object doesn't support this property or method" so i don't think it is even looking at the code beyond this
gizmo1650 is offline   Reply With Quote
Old 04-14-2010, 01:12 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I'm convinced it is *not* that line.

But convince yourself.

Put an alert() just after the comment= line.

Then put one just before and just after the previousElementSibling line. Betcha that narrows it down.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 04-14-2010, 01:17 AM   PM User | #7
gizmo1650
Regular Coder

 
Join Date: Apr 2010
Posts: 163
Thanks: 3
Thanked 25 Times in 25 Posts
gizmo1650 is on a distinguished road
solved.
I ided the div element to html_comment, and that solved the problem. Unfortuantly now i am fining alot of other problems (including previusElementSibling)
gizmo1650 is offline   Reply With Quote
Old 04-14-2010, 01:40 AM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Bizarro. I'd have to guess that you also had a form field with that name, right? And so MSIE tries to find the form field as well as the div. And so getElementById() is trying to process two objects by what it thinks is the same id??? Still...why *that* error message. Joy and light.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 04-14-2010, 08:24 AM   PM User | #9
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,032
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Note that in Internet Explorer, names and IDs are global variables and thus you should NEVER use a global variable or function name which is the same as an HTML element name or ID.

comment=document.getElementById('comment')

You should also avoid giving names or id's to your variables/functions/arguments/forms words which are JavaScript methods/properties/attributes such as 'name' or 'id' or 'value' or 'text' or 'checked' or 'submit' or 'replace' or 'button' or 'radio' or 'parseInt'.

And of course you may not give a variable a name which is a Javascript keyword or event such as alert, case, char, false, int, onload, return, this, void, and so on.

Also avoid words such as description, author, keyword and generator which may appear in META tags.

There is no point in saying "Don't use IE". IE has 62% of the market and any useable web page must be IE compatible.

Last edited by Philip M; 04-14-2010 at 09:11 AM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:41 AM.


Advertisement
Log in to turn off these ads.