Why is this happening? IE7 only error

D

Diogenes

Diogenes wrote:

Oh yeah, I forgot. Click on any calendar day to activate the
script.
 
R

Randy Webb

Diogenes said the following on 3/1/2007 8:47 PM:
Hi All;

Two links here, exactly the same js code. Forms are slightly different.

This works in both FF and IE7

http://68.147.197.6/calgarydj/sampleA.htm

This one FAILS in IE7 (only) with the message ...
Object doesn't support this property or method.

http://68.147.197.6/calgarydj/sampleB.htm

Why? How do you solve something like this?

You start by removing code until you get a minimum case where it fails.
Scale it down to the minimum. Then you will find your error. It has a
lot to do with the format/eval'ing of the 'old' variable.
 
R

RobG

Hi All;

Two links here, exactly the same js code. Forms are
slightly different.

This works in both FF and IE7

http://68.147.197.6/calgarydj/sampleA.htm

This one FAILS in IE7 (only) with the message ...
Object doesn't support this property or method.

http://68.147.197.6/calgarydj/sampleB.htm

Why? How do you solve something like this?

You have a div with id edate and an inferred global variable edate.
IE will create a global variable for the div since it is declared
before you try to assign a value to the inferred global edate.

When you try to assign a date object to edate, IE barfs. There are a
couple of solutions:

- keep the javascript variable edate local to the function (which you
should have done anyway)

- Change the name of either the div or the variable

- Don't use the variable at all (it isn't necessary)

I'd suggest that where you have:

str = year + ',' + (month-1) + ',' + day + ',19,0,0'
old = s3 = 'new Date(' + str + ')'
edate = eval( old )
document.getElementById('title').innerHTML = edate.toString()


you should use (wrapped for posting):

document.getElementById('title').innerHTML =
new Date(year, (month-1), day, 19, 0, 0);


and you will remove the unnecessary use of eval as well.
 
D

Diogenes

RobG said:
You have a div with id edate and an inferred global variable edate.
IE will create a global variable for the div since it is declared
before you try to assign a value to the inferred global edate.

When you try to assign a date object to edate, IE barfs.

Interesting hypothesis. I figured the HTML element id's
would have nothing to do with javascript variables
(different namespace).

I think I'm right here. The *edate* id was deleted and it
made no difference.

There are a
couple of solutions:
I'd suggest that where you have:

str = year + ',' + (month-1) + ',' + day + ',19,0,0'
old = s3 = 'new Date(' + str + ')'
edate = eval( old )
document.getElementById('title').innerHTML = edate.toString()


you should use (wrapped for posting):

document.getElementById('title').innerHTML =
new Date(year, (month-1), day, 19, 0, 0);


and you will remove the unnecessary use of eval as well.

Brilliant suggestion Rob! Much more elegant solution.

I should have thought of that myself! Got into a tunnel
vision mode there, focusing on the wrong thing.

Here it the updated one with your solution.

http://68.147.197.6/calgarydj/sampleC.htm

This still doesn't explain why sampleB did not work. It
should. I'm disappointed in IE7. They had a long time to
catch up to FF, and they still aren't there yet.

Cheers and many thanks,
Jim (from Canada)
 
D

Diogenes

RobG said:
You have a div with id edate and an inferred global variable edate.
IE will create a global variable for the div since it is declared
before you try to assign a value to the inferred global edate.

Actually Rob, you were right on this count too. I did more
testing on SampleB (instead of testing cached pages;-)).

I'm kind of amazed. It must have something to do with IE
document.all object. I don't think there should be overlap.

Cheers
Jim
 
V

VK

Interesting hypothesis. I figured the HTML element id's
would have nothing to do with javascript variables
(different namespace).
I think I'm right here.

Alas you are wrong. Read group FAQ:
<http://www.jibbering.com/faq/index.html#FAQ4_41>

For the minimum sample of RobG explanations and - respectively - your
own problems try this:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script>
function init() {
try {
myDiv = true;
}
catch(e) {
window.alert(e.message);
}
}
window.onload = init;
</script>
</head>

<body>
<div id="myDiv">myDiv</div>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top